X509Certificate.Export Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Esporta l'oggetto corrente X509Certificate in una matrice di byte.
Overload
| Nome | Descrizione |
|---|---|
| Export(X509ContentType) |
Esporta l'oggetto corrente X509Certificate in una matrice di byte in un formato descritto da uno dei X509ContentType valori. |
| Export(X509ContentType, SecureString) |
Esporta l'oggetto corrente X509Certificate in una matrice di byte usando il formato e una password specificati. |
| Export(X509ContentType, String) |
Esporta l'oggetto corrente X509Certificate in una matrice di byte in un formato descritto da uno dei X509ContentType valori e utilizzando la password specificata. |
Export(X509ContentType)
Esporta l'oggetto corrente X509Certificate in una matrice di byte in un formato descritto da uno dei X509ContentType valori.
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()
Parametri
- contentType
- X509ContentType
Uno dei X509ContentType valori che descrive come formattare i dati di output.
Valori restituiti
Matrice di byte che rappresenta l'oggetto corrente X509Certificate .
- Attributi
Eccezioni
Un valore diverso da Cert, SerializedCerto Pkcs12 è stato passato al contentType parametro .
oppure
Impossibile esportare il certificato.
Esempio
L'esempio seguente carica un file di certificato X.509 in un X509Certificate oggetto , esporta il certificato come matrice di byte e quindi importa la matrice di byte in un altro X509Certificate oggetto .
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
Commenti
Il contentType parametro accetta solo i valori seguenti dell'enumerazione X509ContentType : Cert, SerializedCerte Pkcs12. Se si passa qualsiasi altro valore, viene generata un'eccezione CryptographicException .
Si applica a
Export(X509ContentType, SecureString)
Importante
Questa API non è conforme a CLS.
Esporta l'oggetto corrente X509Certificate in una matrice di byte usando il formato e una password specificati.
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()
Parametri
- contentType
- X509ContentType
Uno dei X509ContentType valori che descrive come formattare i dati di output.
- password
- SecureString
Password necessaria per accedere ai dati del certificato X.509.
Valori restituiti
Matrice di byte che rappresenta l'oggetto corrente X509Certificate .
- Attributi
Eccezioni
Un valore diverso da Cert, SerializedCerto Pkcs12 è stato passato al contentType parametro .
oppure
Impossibile esportare il certificato.
Commenti
Il contentType parametro accetta solo i valori seguenti dell'enumerazione X509ContentType : Cert, SerializedCerte Pkcs12. Se si passa qualsiasi altro valore, viene generata un'eccezione CryptographicException .
Important
Non impostare mai come hardcoded una password all'interno del codice sorgente. Le password hardcoded possono essere recuperate da un assembly usando il Ildasm.exe (Disassembler IL), un editor esadecimale o semplicemente aprendo l'assembly in un editor di testo, ad esempio Notepad.exe.
Si applica a
Export(X509ContentType, String)
Esporta l'oggetto corrente X509Certificate in una matrice di byte in un formato descritto da uno dei X509ContentType valori e utilizzando la password specificata.
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()
Parametri
- contentType
- X509ContentType
Uno dei X509ContentType valori che descrive come formattare i dati di output.
- password
- String
Password necessaria per accedere ai dati del certificato X.509.
Valori restituiti
Matrice di byte che rappresenta l'oggetto corrente X509Certificate .
- Attributi
Eccezioni
Un valore diverso da Cert, SerializedCerto Pkcs12 è stato passato al contentType parametro .
oppure
Impossibile esportare il certificato.
Commenti
Il contentType parametro accetta solo i valori seguenti dell'enumerazione X509ContentType : Cert, SerializedCerte Pkcs12. Se si passa qualsiasi altro valore, viene generata un'eccezione CryptographicException .
Important
Non impostare mai come hardcoded una password all'interno del codice sorgente. Le password hardcoded possono essere recuperate da un assembly usando il Ildasm.exe (Disassembler IL), un editor esadecimale o semplicemente aprendo l'assembly in un editor di testo, ad esempio Notepad.exe.