I was using below code for encryption in my project and everything was working fine.
RSACryptoServiceProvider x_alg = new RSACryptoServiceProvider( );
// export only the public key
RSAParameters x_public_params = x_alg.ExportParameters(false);
// export the private key
RSAParameters x_private_params = x_alg.ExportParameters(true);
Now client changed the requirement and he want to store all the RSAParameters value into config file and provided below details for demo
<project name="netCard Server1">
<key length="256"></key>
<D length="64">00000000000000000000000000000000000000000000000000000000000019C5</D>
<DP length="32">00000000000000000000000000000061</DP>
<DQ length="32">00000000000000000000000000000065</DQ>
<Exponent length="6">000DCD</Exponent>
<InverseQ length="32">0000000000000000000000000000003B</InverseQ>
<Modulus length="64">0000000000000000000000000000000000000000000000000000000000002C95</Modulus>
<P length="32">00000000000000000000000000000065</P>
<Q length="32">00000000000000000000000000000071</Q>
<text length ="64">0123456789ABCDEF111111111111111125FE2222222222222233333333334444</text>
<cipher length ="64">0000000000000000000000000000000000000000000000000000000000000000</cipher>
</project>
Now,the problem is that when I am importing the RSAParameters value,I am getting Bad Data Exception
The problem that you have is that the XML that your customer has given you is not in the format required to deserialize to an object of type
RSAParametersI’ve run this code to show what the XML generated by the XML serializer looks like
The output that it generates is something like:
where the … is truncated output. What your customer has supplied looks like a superset of that (key, text and cipher are not in the parameter list) but the format is a bit different.
You can either ask them to supply the data in exactly the required format then serialize from that; or you can accept their format, deserialize it to XML and build the
RSAParametersobject manually by mapping the XML content to the appropriate fields on theRSAParametersobject. You also need to work out what it is that they want to do with the key, text and cipher data as these will be lost in this process.