RSA encryption in C #: which part defines the public key?

I created a new pair of public and private keys and exported it as an XML string:

RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(2048); string publicPrivateKey = RSA.ToXmlString(true); 

The XML line in publicPrivateKey looks like this (lines are shortened for readability):

 <RSAKeyValue> <Modulus>t6tLd1Wi7PEkwPfx9KGP1Ps/5F2saXnOsCE2U....</Modulus> <Exponent>AQAB</Exponent> <P>3LJ5y4Vla7cS3XgmbIH5dQgppUHa+aSWavEOCbDRS/M....</P> <Q>1QyGIAnjv4YLcRVdwXtxWkijc+aZ496qIBZnCAUUD/E....</Q> <DP>0821dc0f+LBKOqIEvj4+2kJrNV5ueQesFBYkEsjPFM....</DP> <DQ>ugSzX2oDJwjdGKG1OOiVcmUWAm6IU4PpOxcUYtY8TC....</DQ> <InverseQ>LDQIQu+LSB6CSZBrGxNQthWi9mkuPGVZyDDr....</InverseQ> <D>qZm2bXKH8WwbsJ8ZlT3S1TbgUifppLrqSRkb8XqEcMv....</D> </RSAKeyValue> 

The generated public key should be used in other applications (PHP / JavaScript / JAVA) to encrypt data. What part of the above XML defines the public key / which part should I send to other application developers?

And on the opposite side: what determines the private key / which part / parts that I have to store in order to decrypt the data encrypted with my public key?

+8
c # cryptography rsa public-key-encryption
source share
2 answers

RSA keys for other parties are difficult to generate in .NET. If you send this XML to them, not all of its partners will be able to use it. The general format of the public key looks something like this:

enter image description here

The xml you received is the private key. To generate a public key, you must use

 string publicPrivateKey = RSA.ToXmlString(false); 

The result will be like this:

 <RSAKeyValue> <Modulus>t6tLd1Wi7PEkwPfx9KGP1Ps/5F2saXnOsCE2U....</Modulus> <Exponent>AQAB</Exponent> </RSAKeyValue> 

You can use other parties to get the key in a different format:

http://www.codeproject.com/KB/security/RSACryptoPad.aspx

To port a Java key to .NET format, you can use this project:

http://www.codeproject.com/KB/security/porting_java_public_key.aspx

+3
source share

The exhibitor and the module determine the public key.

If you use RSA.ToXmlString with a single includePrivateParameters parameter set to false , you will only see the format

 <RSAKeyValue> <Modulus></Modulus> <Exponent></Exponent> </RSAKeyValue> 

exit.

+3
source share

All Articles