X509Certificate.CreateFromCertFile(String) 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.
Skapar ett X.509v3-certifikat från den angivna PKCS7-signerade filen.
public:
static System::Security::Cryptography::X509Certificates::X509Certificate ^ CreateFromCertFile(System::String ^ filename);
public static System.Security.Cryptography.X509Certificates.X509Certificate CreateFromCertFile(string filename);
static member CreateFromCertFile : string -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Shared Function CreateFromCertFile (filename As String) As X509Certificate
Parametrar
- filename
- String
Sökvägen till den PKCS7-signerade fil som X.509-certifikatet ska skapas från.
Returer
Det nyligen skapade X.509-certifikatet.
Undantag
Parametern filename är null.
Exempel
I följande exempel skapas en X509Certificate från en angiven certifieringsfil.
using System;
using System.Security.Cryptography.X509Certificates;
public class X509
{
public static void Main()
{
// The path to the certificate.
string Certificate = "Certificate.cer";
// Load the certificate into an X509Certificate object.
X509Certificate cert = X509Certificate.CreateFromCertFile(Certificate);
// Get the value.
string resultsTrue = cert.ToString(true);
// Display the value to the console.
Console.WriteLine(resultsTrue);
// Get the value.
string resultsFalse = cert.ToString(false);
// Display the value to the console.
Console.WriteLine(resultsFalse);
}
}
Imports System.Security.Cryptography.X509Certificates
Public Class X509
Public Shared Sub Main()
' The path to the certificate.
Dim Certificate As String = "Certificate.cer"
' Load the certificate into an X509Certificate object.
Dim cert As X509Certificate = X509Certificate.CreateFromCertFile(Certificate)
' Get the value.
Dim resultsTrue As String = cert.ToString(True)
' Display the value to the console.
Console.WriteLine(resultsTrue)
' Get the value.
Dim resultsFalse As String = cert.ToString(False)
' Display the value to the console.
Console.WriteLine(resultsFalse)
End Sub
End Class
Kommentarer
ASN.1 DER är det enda certifikatformat som stöds av den här klassen.
Note
Certifikatfilen är inte begränsad till .cer filer. Alla PKCS7-signerade filer kan användas, inklusive en Authenticode-signerad .pfx-fil.