X509Certificate.Export 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將目前 X509Certificate 物件匯出成一個位元組陣列。
多載
| 名稱 | Description |
|---|---|
| Export(X509ContentType) |
將目前 X509Certificate 物件匯出到以其中一個值描述 X509ContentType 的格式的位元組陣列。 |
| Export(X509ContentType, SecureString) |
將目前 X509Certificate 物件匯出為位元組陣列,使用指定格式與密碼。 |
| Export(X509ContentType, String) |
將當前 X509Certificate 物件匯出為位元組陣列,格式依照 X509ContentType 其中一個值描述,並使用指定的密碼。 |
Export(X509ContentType)
將目前 X509Certificate 物件匯出到以其中一個值描述 X509ContentType 的格式的位元組陣列。
public:
virtual cli::array <System::Byte> ^ Export(System::Security::Cryptography::X509Certificates::X509ContentType contentType);
public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType);
[System.Runtime.InteropServices.ComVisible(false)]
public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType);
abstract member Export : System.Security.Cryptography.X509Certificates.X509ContentType -> byte[]
override this.Export : System.Security.Cryptography.X509Certificates.X509ContentType -> byte[]
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member Export : System.Security.Cryptography.X509Certificates.X509ContentType -> byte[]
override this.Export : System.Security.Cryptography.X509Certificates.X509ContentType -> byte[]
Public Overridable Function Export (contentType As X509ContentType) As Byte()
參數
- contentType
- X509ContentType
其中一個 X509ContentType 數值描述了如何格式化輸出資料。
傳回
一個代表當前 X509Certificate 物件的位元組陣列。
- 屬性
例外狀況
範例
以下範例將 X.509 憑證檔案載入物件 X509Certificate ,將憑證匯出為位元組陣列,然後將該位元組陣列匯入另一個 X509Certificate 物件。
using System;
using System.Security.Cryptography.X509Certificates;
public class X509
{
public static void Main()
{
// The path to the certificate.
string Certificate = "test.pfx";
// Load the certificate into an X509Certificate object.
X509Certificate cert = new X509Certificate(Certificate);
byte[] certData = cert.Export(X509ContentType.Cert);
X509Certificate newCert = new X509Certificate(certData);
// Get the value.
string resultsTrue = newCert.ToString(true);
// Display the value to the console.
Console.WriteLine(resultsTrue);
// Get the value.
string resultsFalse = newCert.ToString(false);
// Display the value to the console.
Console.WriteLine(resultsFalse);
}
}
Imports System.Security.Cryptography.X509Certificates
Module X509
Sub Main()
' The path to the certificate.
Dim Certificate As String = "test.pfx"
' Load the certificate into an X509Certificate object.
Dim cert As New X509Certificate(Certificate)
Dim certData As Byte() = cert.Export(X509ContentType.Cert)
Dim newCert As New X509Certificate(certData)
' Get the value.
Dim resultsTrue As String = newCert.ToString(True)
' Display the value to the console.
Console.WriteLine(resultsTrue)
' Get the value.
Dim resultsFalse As String = newCert.ToString(False)
' Display the value to the console.
Console.WriteLine(resultsFalse)
End Sub
End Module
備註
該contentType參數僅接受以下列舉值X509ContentType:Cert、、 SerializedCertPkcs12和 。 若傳遞其他值,則會拋出 a CryptographicException 。
適用於
Export(X509ContentType, SecureString)
重要
此 API 不符合 CLS 規範。
將目前 X509Certificate 物件匯出為位元組陣列,使用指定格式與密碼。
public:
virtual cli::array <System::Byte> ^ Export(System::Security::Cryptography::X509Certificates::X509ContentType contentType, System::Security::SecureString ^ password);
[System.CLSCompliant(false)]
public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType, System.Security.SecureString? password);
[System.CLSCompliant(false)]
public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType, System.Security.SecureString password);
public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType, System.Security.SecureString password);
[<System.CLSCompliant(false)>]
abstract member Export : System.Security.Cryptography.X509Certificates.X509ContentType * System.Security.SecureString -> byte[]
override this.Export : System.Security.Cryptography.X509Certificates.X509ContentType * System.Security.SecureString -> byte[]
abstract member Export : System.Security.Cryptography.X509Certificates.X509ContentType * System.Security.SecureString -> byte[]
override this.Export : System.Security.Cryptography.X509Certificates.X509ContentType * System.Security.SecureString -> byte[]
Public Overridable Function Export (contentType As X509ContentType, password As SecureString) As Byte()
參數
- contentType
- X509ContentType
其中一個 X509ContentType 數值描述了如何格式化輸出資料。
- password
- SecureString
存取 X.509 憑證資料所需的密碼。
傳回
一個代表當前 X509Certificate 物件的位元組陣列。
- 屬性
例外狀況
備註
該contentType參數僅接受以下列舉值X509ContentType:Cert、、 SerializedCertPkcs12和 。 若傳遞其他值,則會拋出 a CryptographicException 。
Important
千萬不要在原始碼裡硬寫密碼。 硬編碼密碼可透過 Ildasm.exe(IL 反組譯器)或十六進位編輯器,或直接在文字編輯器如 Notepad.exe中開啟組合語言擷取。
適用於
Export(X509ContentType, String)
將當前 X509Certificate 物件匯出為位元組陣列,格式依照 X509ContentType 其中一個值描述,並使用指定的密碼。
public:
virtual cli::array <System::Byte> ^ Export(System::Security::Cryptography::X509Certificates::X509ContentType contentType, System::String ^ password);
public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType, string? password);
public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType, string password);
[System.Runtime.InteropServices.ComVisible(false)]
public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType, string password);
abstract member Export : System.Security.Cryptography.X509Certificates.X509ContentType * string -> byte[]
override this.Export : System.Security.Cryptography.X509Certificates.X509ContentType * string -> byte[]
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member Export : System.Security.Cryptography.X509Certificates.X509ContentType * string -> byte[]
override this.Export : System.Security.Cryptography.X509Certificates.X509ContentType * string -> byte[]
Public Overridable Function Export (contentType As X509ContentType, password As String) As Byte()
參數
- contentType
- X509ContentType
其中一個 X509ContentType 數值描述了如何格式化輸出資料。
- password
- String
存取 X.509 憑證資料所需的密碼。
傳回
一個代表當前 X509Certificate 物件的位元組陣列。
- 屬性
例外狀況
備註
該contentType參數僅接受以下列舉值X509ContentType:Cert、、 SerializedCertPkcs12和 。 若傳遞其他值,則會拋出 a CryptographicException 。
Important
千萬不要在原始碼裡硬寫密碼。 硬編碼密碼可透過 Ildasm.exe(IL 反組譯器)或十六進位編輯器,或直接在文字編輯器如 Notepad.exe中開啟組合語言擷取。