RSA.ToXmlString Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Creates and returns an XML string containing the key of the current RSA object.

Namespace:  System.Security.Cryptography
Assembly:  mscorlib.Extensions (in mscorlib.Extensions.dll)

Syntax

'Declaration
Public Overrides Function ToXmlString ( _
    includePrivateParameters As Boolean _
) As String
public override string ToXmlString(
    bool includePrivateParameters
)

Parameters

  • includePrivateParameters
    Type: System.Boolean
    true to include a public and private RSA key; false to include only the public key.

Return Value

Type: System.String
An XML string containing the key of the current RSA object.

Remarks

The ToXmlString method creates an XML string that contains either the public and private key of the current RSA object or contains only the public key of the current RSA object.

Use the ToXmlString method whenever you need to conveniently persist RSA key information. To initialize an RSA object with the key in an XML string, use the FromXmlString method.

Caution noteCaution:

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

When you pass true to the ToXmlString method, the resulting XML string takes the following form:

<RSAKeyValue>
   <Modulus>...</Modulus>
   <Exponent>...</Exponent>
   <P>...</P>
   <Q>...</Q>
   <DP>...</DP>
   <DQ>...</DQ>
   <InverseQ>...</InverseQ>
   <D>...</D>
</RSAKeyValue>

When you pass false to the ToXmlString method, the resulting XML string takes the following form:

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

Version Information

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.