X509Certificate.Export メソッド
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
現在の X509Certificate オブジェクトをバイト配列にエクスポートします。
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 値の 1 つ。
戻り値
- Byte[]
現在の X509Certificate オブジェクトを表すバイトの配列。
- 属性
例外
Cert、SerializedCert、または Pkcs12 以外の値が contentType
パラメーターに渡されました。
または 証明書をエクスポートできませんでした。
例
次の例では、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値のみを受け入れます。 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 オブジェクトをバイト配列にエクスポートします。
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 値の 1 つ。
- password
- SecureString
X.509 証明書データにアクセスするために必要なパスワード。
戻り値
- Byte[]
現在の X509Certificate オブジェクトを表すバイト配列。
- 属性
例外
Cert、SerializedCert、または 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 オブジェクトをバイト配列にエクスポートします。
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 値の 1 つ。
- password
- String
X.509 証明書データにアクセスするために必要なパスワード。
戻り値
- Byte[]
現在の X509Certificate オブジェクトを表すバイトの配列。
- 属性
例外
Cert、SerializedCert、または 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 |