X509Certificate.Export Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Exporta o objeto atual X509Certificate para um array de bytes.
Sobrecargas
| Name | Description |
|---|---|
| Export(X509ContentType) |
Exporta o objeto atual X509Certificate para um array de bytes num formato descrito por um dos X509ContentType valores. |
| Export(X509ContentType, SecureString) |
Exporta o objeto atual X509Certificate para um array de bytes usando o formato especificado e uma palavra-passe. |
| Export(X509ContentType, String) |
Exporta o objeto atual X509Certificate para um array de bytes num formato descrito por um dos X509ContentType valores, usando a palavra-passe especificada. |
Export(X509ContentType)
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
- Origem:
- X509Certificate.cs
Exporta o objeto atual X509Certificate para um array de bytes num 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.
Devoluções
Um array de bytes que representa o objeto atual X509Certificate .
- Atributos
Exceções
Um valor diferente de Cert, , ou SerializedCert foi passado para o Pkcs12contentTypeparâmetro.
-ou-
O certificado não pôde ser exportado.
Exemplos
O exemplo seguinte carrega um ficheiro de certificado X.509 num X509Certificate objeto, exporta o certificado como um array de bytes e depois importa o array 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
Observações
O contentType parâmetro aceita apenas os seguintes valores da X509ContentType enumeração: Cert, SerializedCert, e Pkcs12. Passar qualquer outro valor faz com que a CryptographicException seja lançada.
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 um array de bytes usando o formato especificado e uma palavra-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()
Parâmetros
- contentType
- X509ContentType
Um dos X509ContentType valores que descreve como formatar os dados de saída.
- password
- SecureString
A palavra-passe necessária para aceder aos dados do certificado X.509.
Devoluções
Um array de bytes que representa o objeto atual X509Certificate .
- Atributos
Exceções
Um valor diferente de Cert, , ou SerializedCert foi passado para o Pkcs12contentTypeparâmetro.
-ou-
O certificado não pôde ser exportado.
Observações
O contentType parâmetro aceita apenas os seguintes valores da X509ContentType enumeração: Cert, SerializedCert, e Pkcs12. Passar qualquer outro valor faz com que a CryptographicException seja lançada.
Importante
Nunca codifiquem uma palavra-passe no seu código-fonte. As palavras-passe codificadas fixamente podem ser recuperadas de um assembly usando o Ildasm.exe (IL Disassembler), um editor hexadecimal ou simplesmente abrindo o assembly num editor de texto como o 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 um array de bytes num formato descrito por um dos X509ContentType valores, usando a palavra-passe 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 palavra-passe necessária para aceder aos dados do certificado X.509.
Devoluções
Um array de bytes que representa o objeto atual X509Certificate .
- Atributos
Exceções
Um valor diferente de Cert, , ou SerializedCert foi passado para o Pkcs12contentTypeparâmetro.
-ou-
O certificado não pôde ser exportado.
Observações
O contentType parâmetro aceita apenas os seguintes valores da X509ContentType enumeração: Cert, SerializedCert, e Pkcs12. Passar qualquer outro valor faz com que a CryptographicException seja lançada.
Importante
Nunca codifiquem uma palavra-passe no seu código-fonte. As palavras-passe codificadas fixamente podem ser recuperadas de um assembly usando o Ildasm.exe (IL Disassembler), um editor hexadecimal ou simplesmente abrindo o assembly num editor de texto como o Notepad.exe.