语言

X509Certificate.Export 方法

定义

将当前 X509Certificate 对象导出到字节数组。

重载

名称 说明
Export(X509ContentType)

以值之一X509Certificate描述的格式将当前X509ContentType对象导出到字节数组。

Export(X509ContentType, SecureString)

使用指定的格式和密码将当前 X509Certificate 对象导出到字节数组。

Export(X509ContentType, String)

以值之一X509Certificate描述的格式将当前X509ContentType对象导出到字节数组,并使用指定的密码。

Export(X509ContentType)

Source:
X509Certificate.cs
Source:
X509Certificate.cs
Source:
X509Certificate.cs
Source:
X509Certificate.cs
Source:
X509Certificate.cs

以值之一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描述如何设置输出数据格式的值之一。

返回

Byte[]

表示当前 X509Certificate 对象的字节数组。

特性

例外

除其他值外 Cert, SerializedCert或 Pkcs12 已传递给 contentType 参数。

-或-

无法导出证书。

示例

以下示例将 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、 SerializedCert和 Pkcs12。 传递任何其他值会导致引发。CryptographicException

适用于

Export(X509ContentType, SecureString)

Source:
X509Certificate.cs
Source:
X509Certificate.cs
Source:
X509Certificate.cs
Source:
X509Certificate.cs
Source:
X509Certificate.cs

重要

此 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 证书数据所需的密码。

返回

Byte[]

表示当前 X509Certificate 对象的字节数组。

特性

例外

除其他值外 Cert, SerializedCert或 Pkcs12 已传递给 contentType 参数。

-或-

无法导出证书。

注解

该 contentType 参数仅接受枚举的 X509ContentType 以下值: Cert、 SerializedCert和 Pkcs12。 传递任何其他值会导致引发。CryptographicException

Important

从不对源代码中的密码进行硬编码。 可以使用 Ildasm.exe(IL 反汇编程序)、十六进制编辑器或直接在文本编辑器(如 Notepad.exe)中打开程序集来检索硬编码的密码。

适用于

Export(X509ContentType, String)

Source:
X509Certificate.cs
Source:
X509Certificate.cs
Source:
X509Certificate.cs
Source:
X509Certificate.cs
Source:
X509Certificate.cs

以值之一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 证书数据所需的密码。

返回

Byte[]

表示当前 X509Certificate 对象的字节数组。

特性

例外

除其他值外 Cert, SerializedCert或 Pkcs12 已传递给 contentType 参数。

-或-

无法导出证书。

注解

该 contentType 参数仅接受枚举的 X509ContentType 以下值: Cert、 SerializedCert和 Pkcs12。 传递任何其他值会导致引发。CryptographicException

Important

从不对源代码中的密码进行硬编码。 可以使用 Ildasm.exe(IL 反汇编程序)、十六进制编辑器或直接在文本编辑器(如 Notepad.exe)中打开程序集来检索硬编码的密码。

适用于