X509Certificate.Export Méthode

Définition

Exporte l’objet actuel X509Certificate vers un tableau d’octets.

Surcharges

Nom Description
Export(X509ContentType)

Exporte l’objet actuel X509Certificate vers un tableau d’octets dans un format décrit par l’une X509ContentType des valeurs.

Export(X509ContentType, SecureString)

Exporte l’objet actuel X509Certificate vers un tableau d’octets à l’aide du format spécifié et d’un mot de passe.

Export(X509ContentType, String)

Exporte l’objet actuel X509Certificate dans un tableau d’octets dans un format décrit par l’une X509ContentType des valeurs et à l’aide du mot de passe spécifié.

Export(X509ContentType)

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

Exporte l’objet actuel X509Certificate vers un tableau d’octets dans un format décrit par l’une X509ContentType des valeurs.

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()

Paramètres

contentType
X509ContentType

Une des X509ContentType valeurs qui explique comment mettre en forme les données de sortie.

Retours

Byte[]

Tableau d’octets qui représente l’objet actuel X509Certificate .

Attributs

Exceptions

Valeur autre que Cert, SerializedCertou Pkcs12 a été passée au contentType paramètre.

- ou -

Impossible d’exporter le certificat.

Exemples

L’exemple suivant charge un fichier de certificat X.509 dans un X509Certificate objet, exporte le certificat en tant que tableau d’octets, puis importe le tableau d’octets dans un autre X509Certificate objet.

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

Remarques

Le contentType paramètre accepte uniquement les valeurs suivantes de l’énumération X509ContentType : Cert, SerializedCertet Pkcs12. La transmission d’une autre valeur entraîne la levée d’une CryptographicException valeur.

S’applique à

Export(X509ContentType, SecureString)

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

Important

Cette API n’est pas conforme CLS.

Exporte l’objet actuel X509Certificate vers un tableau d’octets à l’aide du format spécifié et d’un mot de passe.

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()

Paramètres

contentType
X509ContentType

Une des X509ContentType valeurs qui explique comment mettre en forme les données de sortie.

password
SecureString

Mot de passe requis pour accéder aux données du certificat X.509.

Retours

Byte[]

Tableau d’octets qui représente l’objet actuel X509Certificate .

Attributs

Exceptions

Valeur autre que Cert, SerializedCertou Pkcs12 a été passée au contentType paramètre.

- ou -

Impossible d’exporter le certificat.

Remarques

Le contentType paramètre accepte uniquement les valeurs suivantes de l’énumération X509ContentType : Cert, SerializedCertet Pkcs12. La transmission d’une autre valeur entraîne la levée d’une CryptographicException valeur.

Important

Ne codez jamais en dur un mot de passe dans votre code source. Les mots de passe codés en dur peuvent être récupérés à partir d’un assembly à l’aide du Ildasm.exe (désassembleur IL), d’un éditeur hexadécimal ou en ouvrant simplement l’assembly dans un éditeur de texte tel que Notepad.exe.

S’applique à

Export(X509ContentType, String)

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

Exporte l’objet actuel X509Certificate dans un tableau d’octets dans un format décrit par l’une X509ContentType des valeurs et à l’aide du mot de passe spécifié.

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()

Paramètres

contentType
X509ContentType

Une des X509ContentType valeurs qui explique comment mettre en forme les données de sortie.

password
String

Mot de passe requis pour accéder aux données du certificat X.509.

Retours

Byte[]

Tableau d’octets qui représente l’objet actuel X509Certificate .

Attributs

Exceptions

Valeur autre que Cert, SerializedCertou Pkcs12 a été passée au contentType paramètre.

- ou -

Impossible d’exporter le certificat.

Remarques

Le contentType paramètre accepte uniquement les valeurs suivantes de l’énumération X509ContentType : Cert, SerializedCertet Pkcs12. La transmission d’une autre valeur entraîne la levée d’une CryptographicException valeur.

Important

Ne codez jamais en dur un mot de passe dans votre code source. Les mots de passe codés en dur peuvent être récupérés à partir d’un assembly à l’aide du Ildasm.exe (désassembleur IL), d’un éditeur hexadécimal ou en ouvrant simplement l’assembly dans un éditeur de texte tel que Notepad.exe.

S’applique à