X509Certificate2.Export(X509ContentType, String) 方法

定義

以其中一個 X509Certificate 值所描述的格式,並使用指定的密碼,將目前的 X509ContentType 物件匯出至位元組陣列。Exports the current X509Certificate object to a byte array in a format described by one of the X509ContentType values, and using the specified password.

public:
 override cli::array <System::Byte> ^ Export(System::Security::Cryptography::X509Certificates::X509ContentType contentType, System::String ^ password);
public override byte[] Export (System.Security.Cryptography.X509Certificates.X509ContentType contentType, string password);
override this.Export : System.Security.Cryptography.X509Certificates.X509ContentType * string -> byte[]
Public Overrides Function Export (contentType As X509ContentType, password As String) As Byte()

參數

contentType
X509ContentType

其中一個 X509ContentType 值,其描述如何格式化輸出資料。One of the X509ContentType values that describes how to format the output data.

password
String

存取 X.509 憑證資料所需的密碼。The password required to access the X.509 certificate data.

傳回

Byte[]

位元組的陣列,表示目前的 X509Certificate 物件。An array of bytes that represents the current X509Certificate object.

例外狀況

CertSerializedCertPkcs12 以外的值傳遞至 contentType 參數。A value other than Cert, SerializedCert, or Pkcs12 was passed to the contentType parameter.

-或--or- 無法匯出憑證。The certificate could not be exported.

備註

contentType參數只接受下列 X509ContentType 列舉值: CertSerializedCertPkcs12The contentType parameter accepts only the following values of the X509ContentType enumeration: Cert, SerializedCert, and Pkcs12. 傳遞任何其他值會導致擲回 CryptographicExceptionPassing any other value causes a CryptographicException to be thrown.

重要

請勿在原始程式碼中將密碼硬編碼。Never hard code a password within your source code. 您可以使用 Ildasm.exe (IL 解譯器) 工具、十六進位編輯器,或直接在文字編輯器(例如 Notepad.exe)中開啟元件,從元件中取出硬式編碼的密碼。Hard-coded passwords can be retrieved from an assembly using the Ildasm.exe (IL Disassembler) tool, a hex editor, or by simply opening the assembly in a text editor such as Notepad.exe.

適用於