X509Certificate.Export Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Exporta o objeto atual X509Certificate para uma matriz de bytes.
Sobrecargas
| Nome | Description |
|---|---|
| Export(X509ContentType) |
Exporta o objeto atual X509Certificate para uma matriz de bytes em um formato descrito por um dos X509ContentType valores. |
| Export(X509ContentType, SecureString) |
Exporta o objeto atual X509Certificate para uma matriz de bytes usando o formato especificado e uma senha. |
| Export(X509ContentType, String) |
Exporta o objeto atual X509Certificate para uma matriz de bytes em um formato descrito por um dos X509ContentType valores e usando a senha especificada. |
Export(X509ContentType)
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
Exporta o objeto atual X509Certificate para uma matriz de bytes em um formato descrito por um dos X509ContentType valores.
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()
Parâmetros
- contentType
- X509ContentType
Um dos X509ContentType valores que descreve como formatar os dados de saída.
Retornos
Uma matriz de bytes que representa o objeto atual X509Certificate .
- Atributos
Exceções
Um valor diferente Certde , SerializedCertou Pkcs12 foi passado para o contentType parâmetro.
- ou -
Não foi possível exportar o certificado.
Exemplos
O exemplo a seguir carrega um arquivo de certificado X.509 em um X509Certificate objeto, exporta o certificado como uma matriz de bytes e importa a matriz de bytes para outro X509Certificate objeto.
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
Comentários
O contentType parâmetro aceita apenas os seguintes valores da X509ContentType enumeração: Cert, SerializedCerte Pkcs12. Passar qualquer outro valor faz com que um CryptographicException seja gerado.
Aplica-se a
Export(X509ContentType, SecureString)
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
Importante
Esta API não está em conformidade com CLS.
Exporta o objeto atual X509Certificate para uma matriz de bytes usando o formato especificado e uma senha.
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()
Parâmetros
- contentType
- X509ContentType
Um dos X509ContentType valores que descreve como formatar os dados de saída.
- password
- SecureString
A senha necessária para acessar os dados do certificado X.509.
Retornos
Uma matriz de bytes que representa o objeto atual X509Certificate .
- Atributos
Exceções
Um valor diferente Certde , SerializedCertou Pkcs12 foi passado para o contentType parâmetro.
- ou -
Não foi possível exportar o certificado.
Comentários
O contentType parâmetro aceita apenas os seguintes valores da X509ContentType enumeração: Cert, SerializedCerte Pkcs12. Passar qualquer outro valor faz com que um CryptographicException seja gerado.
Importante
Nunca codifique uma senha no código-fonte. Senhas codificadas em código podem ser recuperadas de um assembly usando o Ildasm.exe (IL Disassembler), um editor hex ou simplesmente abrindo o assembly em um editor de texto, como Notepad.exe.
Aplica-se a
Export(X509ContentType, String)
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
Exporta o objeto atual X509Certificate para uma matriz de bytes em um formato descrito por um dos X509ContentType valores e usando a senha especificada.
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()
Parâmetros
- contentType
- X509ContentType
Um dos X509ContentType valores que descreve como formatar os dados de saída.
- password
- String
A senha necessária para acessar os dados do certificado X.509.
Retornos
Uma matriz de bytes que representa o objeto atual X509Certificate .
- Atributos
Exceções
Um valor diferente Certde , SerializedCertou Pkcs12 foi passado para o contentType parâmetro.
- ou -
Não foi possível exportar o certificado.
Comentários
O contentType parâmetro aceita apenas os seguintes valores da X509ContentType enumeração: Cert, SerializedCerte Pkcs12. Passar qualquer outro valor faz com que um CryptographicException seja gerado.
Importante
Nunca codifique uma senha no código-fonte. Senhas codificadas em código podem ser recuperadas de um assembly usando o Ildasm.exe (IL Disassembler), um editor hex ou simplesmente abrindo o assembly em um editor de texto, como Notepad.exe.