Share via


RSA.ToXmlString(Boolean) 方法

定義

建立並傳回 XML 字串,其中包含目前 RSA 物件的金鑰。

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 則只會加入公開金鑰。

傳回

XML 字串,其中包含目前 RSA 物件的金鑰。

例外狀況

僅限 .NET Core 與 .NET 5+:在所有情況下。

備註

方法 ToXmlString 會建立 XML 字串,其中包含目前 RSA 對象的公開和私鑰,或只包含目前 RSA 物件的公鑰。

ToXmlString每當您需要方便保存 RSA 金鑰資訊時,請使用 方法。 若要使用 XML 字串中的索引鍵初始化 RSA 物件,請使用 FromXmlString 方法。

警告

將包含私鑰的 XML 字串保存到不安全的位置是安全性威脅。 如果惡意第三方可以存取您的私鑰,應用程式的安全性可能會遭到入侵。 若要安全地保存私鑰,請使用安全金鑰容器。 如需在金鑰容器中保存私鑰的詳細資訊,請參閱 如何:將非對稱金鑰儲存在金鑰容器中

當您傳遞 trueToXmlString 方法時,產生的 XML 字串會採用下列形式:

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

當您傳遞 falseToXmlString 方法時,產生的 XML 字串會採用下列形式:

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

適用於

另請參閱