Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I've generated a new public/private key pair and exported it as an XML string:

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

The XML string in publicPrivateKey looks like this (strings 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 apps (PHP / JavaScript / JAVA) to encrypt data. What part of the above XML defines the public key / what part do I have to send to the developers of the other apps?

And on the opposite side: What defines the private key / which part/parts do I have to store to be able to decrypt the data encrypted by my public key?

like image 392
Mike Avatar asked Jul 09 '11 17:07

Mike


People also ask

What is the RSA formula for encryption?

To encrypt a plaintext M using an RSA public key we simply represent the plaintext as a number between 0 and N-1 and then compute the ciphertext C as: C = Me mod N.

Which algorithm is used in RSA?

The public and private key generation algorithm is the most complex part of RSA cryptography. Two large prime numbers, p and q, are generated using the Rabin-Miller primality test algorithm. A modulus, n, is calculated by multiplying p and q.


1 Answers

Exponent and modulus define the public key.

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

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

output.

like image 181
jason Avatar answered Nov 09 '22 18:11

jason