X509Certificate.Export Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Exporterar det aktuella X509Certificate objektet till en bytematris.
Överlagringar
| Name | Description |
|---|---|
| Export(X509ContentType) |
Exporterar det aktuella X509Certificate objektet till en bytematris i ett format som beskrivs av något av X509ContentType värdena. |
| Export(X509ContentType, SecureString) |
Exporterar det aktuella X509Certificate objektet till en bytematris med det angivna formatet och ett lösenord. |
| Export(X509ContentType, String) |
Exporterar det aktuella X509Certificate objektet till en bytematris i ett format som beskrivs av ett av X509ContentType värdena och med det angivna lösenordet. |
Export(X509ContentType)
Exporterar det aktuella X509Certificate objektet till en bytematris i ett format som beskrivs av något av X509ContentType värdena.
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()
Parametrar
- contentType
- X509ContentType
Ett av de X509ContentType värden som beskriver hur du formaterar utdata.
Returer
En matris med byte som representerar det aktuella X509Certificate objektet.
- Attribut
Undantag
Ett annat värde än Cert, SerializedCerteller Pkcs12 skickades till parametern contentType .
-eller-
Det gick inte att exportera certifikatet.
Exempel
I följande exempel läses en X.509-certifikatfil in i ett X509Certificate objekt, certifikatet exporteras som en bytematris och sedan importeras bytematrisen till ett annat X509Certificate objekt.
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
Kommentarer
Parametern contentType accepterar endast följande värden för X509ContentType uppräkningen: Cert, SerializedCertoch Pkcs12. Om du skickar ett annat värde genereras ett CryptographicException värde.
Gäller för
Export(X509ContentType, SecureString)
Viktigt!
Detta API uppfyller inte CLS.
Exporterar det aktuella X509Certificate objektet till en bytematris med det angivna formatet och ett lösenord.
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()
Parametrar
- contentType
- X509ContentType
Ett av de X509ContentType värden som beskriver hur du formaterar utdata.
- password
- SecureString
Lösenordet som krävs för att komma åt X.509-certifikatdata.
Returer
En bytematris som representerar det aktuella X509Certificate objektet.
- Attribut
Undantag
Ett annat värde än Cert, SerializedCerteller Pkcs12 skickades till parametern contentType .
-eller-
Det gick inte att exportera certifikatet.
Kommentarer
Parametern contentType accepterar endast följande värden för X509ContentType uppräkningen: Cert, SerializedCertoch Pkcs12. Om du skickar ett annat värde genereras ett CryptographicException värde.
Important
Hårdkoda aldrig ett lösenord i källkoden. Hårdkodade lösenord kan hämtas från en sammansättning med hjälp avIldasm.exe (IL Disassembler), en hexredigerare eller genom att helt enkelt öppna sammansättningen i en textredigerare som Notepad.exe.
Gäller för
Export(X509ContentType, String)
Exporterar det aktuella X509Certificate objektet till en bytematris i ett format som beskrivs av ett av X509ContentType värdena och med det angivna lösenordet.
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()
Parametrar
- contentType
- X509ContentType
Ett av de X509ContentType värden som beskriver hur du formaterar utdata.
- password
- String
Lösenordet som krävs för att komma åt X.509-certifikatdata.
Returer
En matris med byte som representerar det aktuella X509Certificate objektet.
- Attribut
Undantag
Ett annat värde än Cert, SerializedCerteller Pkcs12 skickades till parametern contentType .
-eller-
Det gick inte att exportera certifikatet.
Kommentarer
Parametern contentType accepterar endast följande värden för X509ContentType uppräkningen: Cert, SerializedCertoch Pkcs12. Om du skickar ett annat värde genereras ett CryptographicException värde.
Important
Hårdkoda aldrig ett lösenord i källkoden. Hårdkodade lösenord kan hämtas från en sammansättning med hjälp avIldasm.exe (IL Disassembler), en hexredigerare eller genom att helt enkelt öppna sammansättningen i en textredigerare som Notepad.exe.