X509Certificate.Export 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将当前 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
以 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 namespace System;
using namespace System::Security::Cryptography::X509Certificates;
int main()
{
// The path to the certificate.
String^ Certificate = L"test.pfx";
// Load the certificate into an X509Certificate object.
X509Certificate^ cert = gcnew X509Certificate( Certificate );
array<Byte>^certData = cert->Export( X509ContentType::Cert );
X509Certificate^ newCert = gcnew 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 );
}
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
重要
此 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、 SerializedCert和 Pkcs12。 传递任何其他值都会导致 CryptographicException 引发 。
重要
切勿在源代码中对密码进行硬编码。 可以使用 Ildasm.exe (IL 反汇编程序) (十六进制编辑器)或通过在文本编辑器(如 Notepad.exe)中打开程序集来检索硬编码密码。
适用于
Export(X509ContentType, String)
- 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 证书数据所需的密码。
返回
表示当前 X509Certificate 对象的字节数组。
- 属性
例外
注解
参数 contentType
仅接受枚举的 X509ContentType 以下值: Cert、 SerializedCert和 Pkcs12。 传递任何其他值都会导致 CryptographicException 引发 。
重要
切勿在源代码中对密码进行硬编码。 可以使用 Ildasm.exe (IL 反汇编程序) (十六进制编辑器)或通过在文本编辑器(如 Notepad.exe)中打开程序集来检索硬编码密码。