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?
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.