RSA.ToXmlString(Boolean) 方法

定義

建立並傳回 XML 字串,其中包含目前 RSA 物件的金鑰。Creates and returns an XML string containing the key of the current RSA object.

public:
 override System::String ^ ToXmlString(bool includePrivateParameters);
public override string ToXmlString (bool includePrivateParameters);
override this.ToXmlString : bool -> string
Public Overrides Function ToXmlString (includePrivateParameters As Boolean) As String

參數

includePrivateParameters
Boolean

若是 true 則會加入公開和私密 RSA 金鑰;false 則只會加入公開金鑰。true to include a public and private RSA key; false to include only the public key.

傳回

String

XML 字串,其中包含目前 RSA 物件的金鑰。An XML string containing the key of the current RSA object.

例外狀況

僅限 .NET 5+ 與 .NET Core:不支援此成員。.NET 5+ and .NET Core only: This member is not supported.

備註

ToXmlString方法會建立 XML 字串,其中包含目前物件的公開和私密金鑰, RSA 或只包含目前物件的公開金鑰 RSAThe 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.

ToXmlString當您需要方便地保存 RSA 金鑰資訊時,請使用方法。Use the ToXmlString method whenever you need to conveniently persist RSA key information. 若要 RSA 使用 XML 字串中的索引鍵來初始化物件,請使用 FromXmlString 方法。To initialize an RSA object with the key in an XML string, use the FromXmlString method.

警告

將包含私密金鑰的 XML 字串保存到不安全的位置是一項安全性威脅。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.

當您傳遞 trueToXmlString 方法時,產生的 XML 字串會採用下列格式: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>  

當您傳遞 falseToXmlString 方法時,產生的 XML 字串會採用下列格式:When you pass false to the ToXmlString method, the resulting XML string takes the following form:

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

適用於