X509Certificate.CreateFromCertFile(String) Metoda

Definicja

Tworzy certyfikat X.509v3 z określonego podpisanego pliku PKCS7.

public:
 static System::Security::Cryptography::X509Certificates::X509Certificate ^ CreateFromCertFile(System::String ^ filename);
public static System.Security.Cryptography.X509Certificates.X509Certificate CreateFromCertFile (string filename);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static System.Security.Cryptography.X509Certificates.X509Certificate CreateFromCertFile (string filename);
static member CreateFromCertFile : string -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
static member CreateFromCertFile : string -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Shared Function CreateFromCertFile (filename As String) As X509Certificate

Parametry

filename
String

Ścieżka podpisanego pliku PKCS7, z którego ma zostać utworzony certyfikat X.509.

Zwraca

X509Certificate

Nowo utworzony certyfikat X.509.

Atrybuty

Wyjątki

Parametr filename to null.

Przykłady

Poniższy przykład tworzy obiekt z X509Certificate określonego pliku certyfikacji.

using namespace System;
using namespace System::Security::Cryptography::X509Certificates;
int 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 );
}

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

Uwagi

ASN.1 DER jest jedynym formatem certyfikatu obsługiwanym przez tę klasę.

Uwaga

Plik certyfikatu nie jest ograniczony do plików cer. Można użyć dowolnego podpisanego pliku PKCS7, w tym pliku pfx podpisanego przez aplikację Authenticode.

Dotyczy