X509Certificate.Export メソッド

定義

現在の X509Certificate オブジェクトをバイト配列にエクスポートします。

オーバーロード

Export(X509ContentType)

いずれかの X509Certificate 値で記述する形式で、現在の X509ContentType オブジェクトをバイト配列にエクスポートします。

Export(X509ContentType, SecureString)

形式とパスワードを指定して、現在の X509Certificate オブジェクトをバイト配列にエクスポートします。

Export(X509ContentType, String)

指定したパスワードを使用し、いずれかの X509Certificate 値で記述する形式で、現在の X509ContentType オブジェクトをバイト配列にエクスポートします。

Export(X509ContentType)

いずれかの X509Certificate 値で記述する形式で、現在の X509ContentType オブジェクトをバイト配列にエクスポートします。

C#
public virtual byte[] Export (System.Security.Cryptography.X509Certificates.X509ContentType contentType);
C#
[System.Runtime.InteropServices.ComVisible(false)]
public virtual byte[] Export (System.Security.Cryptography.X509Certificates.X509ContentType contentType);

パラメーター

contentType
X509ContentType

出力データの形式を記述する X509ContentType 値の 1 つ。

戻り値

Byte[]

現在の X509Certificate オブジェクトを表すバイトの配列。

属性

例外

CertSerializedCert、または Pkcs12 以外の値が contentType パラメーターに渡されました。

または 証明書をエクスポートできませんでした。

次の例では、X.509 証明書ファイルを X509Certificate オブジェクトに読み込み、証明書をバイト配列としてエクスポートしてから、バイト配列を別 X509Certificate のオブジェクトにインポートします。

C#
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);
    }
}

注釈

このパラメーターはcontentType、列挙体の次のX509ContentType値のみを受け入れます。 CertSerializedCertPkcs12 他の値を渡すと、a CryptographicException がスローされます。

適用対象

.NET 7 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

Export(X509ContentType, SecureString)

重要

この API は CLS 準拠ではありません。

形式とパスワードを指定して、現在の X509Certificate オブジェクトをバイト配列にエクスポートします。

C#
[System.CLSCompliant(false)]
public virtual byte[] Export (System.Security.Cryptography.X509Certificates.X509ContentType contentType, System.Security.SecureString? password);
C#
[System.CLSCompliant(false)]
public virtual byte[] Export (System.Security.Cryptography.X509Certificates.X509ContentType contentType, System.Security.SecureString password);
C#
public virtual byte[] Export (System.Security.Cryptography.X509Certificates.X509ContentType contentType, System.Security.SecureString password);

パラメーター

contentType
X509ContentType

出力データの形式を記述する X509ContentType 値の 1 つ。

password
SecureString

X.509 証明書データにアクセスするために必要なパスワード。

戻り値

Byte[]

現在の X509Certificate オブジェクトを表すバイト配列。

属性

例外

CertSerializedCert、または Pkcs12 以外の値が contentType パラメーターに渡されました。

または 証明書をエクスポートできませんでした。

注釈

このパラメーターはcontentType、列挙体の次のX509ContentType値のみを受け入れます。 CertSerializedCertPkcs12 他の値を渡すと、a CryptographicException がスローされます。

重要

ソース コード内でパスワードをハードコードしないでください。 ハードコーディングされたパスワードは、 Ildasm.exe (IL 逆アセンブラー)、16 進エディター、または単に Notepad.exe などのテキスト エディターでアセンブリを開くだけで、アセンブリから取得できます。

適用対象

.NET 7 およびその他のバージョン
製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1

Export(X509ContentType, String)

指定したパスワードを使用し、いずれかの X509Certificate 値で記述する形式で、現在の X509ContentType オブジェクトをバイト配列にエクスポートします。

C#
public virtual byte[] Export (System.Security.Cryptography.X509Certificates.X509ContentType contentType, string? password);
C#
public virtual byte[] Export (System.Security.Cryptography.X509Certificates.X509ContentType contentType, string password);
C#
[System.Runtime.InteropServices.ComVisible(false)]
public virtual byte[] Export (System.Security.Cryptography.X509Certificates.X509ContentType contentType, string password);

パラメーター

contentType
X509ContentType

出力データの形式を記述する X509ContentType 値の 1 つ。

password
String

X.509 証明書データにアクセスするために必要なパスワード。

戻り値

Byte[]

現在の X509Certificate オブジェクトを表すバイトの配列。

属性

例外

CertSerializedCert、または Pkcs12 以外の値が contentType パラメーターに渡されました。

または 証明書をエクスポートできませんでした。

注釈

このパラメーターはcontentType、列挙体の次のX509ContentType値のみを受け入れます。 CertSerializedCertPkcs12 他の値を渡すと、a CryptographicException がスローされます。

重要

ソース コード内でパスワードをハードコードしないでください。 ハードコーディングされたパスワードは、 Ildasm.exe (IL 逆アセンブラー)、16 進エディター、または単に Notepad.exe などのテキスト エディターでアセンブリを開くだけで、アセンブリから取得できます。

適用対象

.NET 7 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1