Creates and returns an XML string containing the key of the current System.Security.Cryptography.RSA object.
![]()
An XML string containing the key of the current System.Security.Cryptography.RSA object.
The RSA.ToXmlString(bool) method creates an XML string that contains either the public and private key of the current System.Security.Cryptography.RSA object or contains only the public key of the current System.Security.Cryptography.RSA object.
Use the RSA.ToXmlString(bool) method whenever you need to conveniently persist RSA key information. To initialize an System.Security.Cryptography.RSA object with the key in an XML string, use the RSA.FromXmlString(string) method.
Persisting an XML string containing a private key to an insecure location is a security threat. The security of your application can be compromised if a malicious third party can access your private key. To safely persist a private key, use a secure key container. For more information about persisting private keys in a key container, see How to: Store Asymmetric Keys in a Key Container.
When you pass true to the RSA.ToXmlString(bool) method, the resulting XML string takes the following form:
Example
<RSAKeyValue> <Modulus>…</Modulus> <Exponent>…</Exponent> <P>…</P> <Q>…</Q> <DP>…</DP> <DQ>…</DQ> <InverseQ>…</InverseQ> <D>…</D> </RSAKeyValue>
When you pass false to the RSA.ToXmlString(bool) method, the resulting XML string takes the following form:
Example
<RSAKeyValue> <Modulus>…</Modulus> <Exponent>…</Exponent> </RSAKeyValue>