X509Certificate.Export Methode

Definition

Exportiert das aktuelle X509Certificate Objekt in ein Bytearray.

Überlädt

Name Beschreibung
Export(X509ContentType)

Exportiert das aktuelle X509Certificate Objekt in ein Bytearray in einem Format, das durch einen der X509ContentType Werte beschrieben wird.

Export(X509ContentType, SecureString)

Exportiert das aktuelle X509Certificate Objekt mithilfe des angegebenen Formats und eines Kennworts in ein Bytearray.

Export(X509ContentType, String)

Exportiert das aktuelle X509Certificate Objekt in ein Bytearray in einem Format, das durch einen der X509ContentType Werte beschrieben wird, und verwendet das angegebene Kennwort.

Export(X509ContentType)

Exportiert das aktuelle X509Certificate Objekt in ein Bytearray in einem Format, das durch einen der X509ContentType Werte beschrieben wird.

public:
 virtual cli::array <System::Byte> ^ Export(System::Security::Cryptography::X509Certificates::X509ContentType contentType);
[System.Runtime.InteropServices.ComVisible(false)]
public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType);
public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType);
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member Export : System.Security.Cryptography.X509Certificates.X509ContentType -> byte[]
override this.Export : System.Security.Cryptography.X509Certificates.X509ContentType -> byte[]
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()

Parameter

contentType
X509ContentType

Einer der X509ContentType Werte, der beschreibt, wie die Ausgabedaten formatiert werden.

Gibt zurück

Byte[]

Ein Array von Bytes, das das aktuelle X509Certificate Objekt darstellt.

Attribute

Ausnahmen

Ein anderer Wert als Cert, SerializedCertoder Pkcs12 wurde an den contentType Parameter übergeben.

-oder-

Das Zertifikat konnte nicht exportiert werden.

Beispiele

Im folgenden Beispiel wird eine X.509-Zertifikatdatei in ein X509Certificate Objekt geladen, das Zertifikat als Bytearray exportiert und anschließend das Bytearray in ein anderes X509Certificate Objekt importiert.

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

Hinweise

Der contentType Parameter akzeptiert nur die folgenden Werte der X509ContentType Enumeration: Cert, SerializedCert, und Pkcs12. Wenn sie einen anderen Wert übergeben, wird ein CryptographicException Fehler ausgelöst.

Gilt für:

Export(X509ContentType, SecureString)

Wichtig

Diese API ist nicht CLS-kompatibel.

Exportiert das aktuelle X509Certificate Objekt mithilfe des angegebenen Formats und eines Kennworts in ein Bytearray.

public:
 virtual cli::array <System::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)]
public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType, System.Security.SecureString password);
abstract member Export : System.Security.Cryptography.X509Certificates.X509ContentType * System.Security.SecureString -> byte[]
override this.Export : System.Security.Cryptography.X509Certificates.X509ContentType * System.Security.SecureString -> byte[]
[<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[]
Public Overridable Function Export (contentType As X509ContentType, password As SecureString) As Byte()

Parameter

contentType
X509ContentType

Einer der X509ContentType Werte, der beschreibt, wie die Ausgabedaten formatiert werden.

password
SecureString

Das Kennwort, das für den Zugriff auf die X.509-Zertifikatdaten erforderlich ist.

Gibt zurück

Byte[]

Ein Bytearray, das das aktuelle X509Certificate Objekt darstellt.

Attribute

Ausnahmen

Ein anderer Wert als Cert, SerializedCertoder Pkcs12 wurde an den contentType Parameter übergeben.

-oder-

Das Zertifikat konnte nicht exportiert werden.

Hinweise

Der contentType Parameter akzeptiert nur die folgenden Werte der X509ContentType Enumeration: Cert, SerializedCert, und Pkcs12. Wenn sie einen anderen Wert übergeben, wird ein CryptographicException Fehler ausgelöst.

Important

Schreiben Sie niemals ein Kennwort in Ihrem Quellcode fest. Hartcodierte Kennwörter können mithilfe des Ildasm.exe (IL Disassembler), eines Hex-Editors oder durch einfaches Öffnen der Assembly in einem Text-Editor wie Notepad.exeaus einer Assembly abgerufen werden.

Gilt für:

Export(X509ContentType, String)

Exportiert das aktuelle X509Certificate Objekt in ein Bytearray in einem Format, das durch einen der X509ContentType Werte beschrieben wird, und verwendet das angegebene Kennwort.

public:
 virtual cli::array <System::Byte> ^ Export(System::Security::Cryptography::X509Certificates::X509ContentType contentType, System::String ^ password);
[System.Runtime.InteropServices.ComVisible(false)]
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)>]
abstract member Export : System.Security.Cryptography.X509Certificates.X509ContentType * string -> byte[]
override this.Export : System.Security.Cryptography.X509Certificates.X509ContentType * string -> byte[]
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()

Parameter

contentType
X509ContentType

Einer der X509ContentType Werte, der beschreibt, wie die Ausgabedaten formatiert werden.

password
String

Das Kennwort, das für den Zugriff auf die X.509-Zertifikatdaten erforderlich ist.

Gibt zurück

Byte[]

Ein Array von Bytes, das das aktuelle X509Certificate Objekt darstellt.

Attribute

Ausnahmen

Ein anderer Wert als Cert, SerializedCertoder Pkcs12 wurde an den contentType Parameter übergeben.

-oder-

Das Zertifikat konnte nicht exportiert werden.

Hinweise

Der contentType Parameter akzeptiert nur die folgenden Werte der X509ContentType Enumeration: Cert, SerializedCert, und Pkcs12. Wenn sie einen anderen Wert übergeben, wird ein CryptographicException Fehler ausgelöst.

Important

Schreiben Sie niemals ein Kennwort in Ihrem Quellcode fest. Hartcodierte Kennwörter können mithilfe des Ildasm.exe (IL Disassembler), eines Hex-Editors oder durch einfaches Öffnen der Assembly in einem Text-Editor wie Notepad.exeaus einer Assembly abgerufen werden.

Gilt für: