Прочитать на английском

Поделиться через


X509Certificate.CreateFromCertFile(String) Метод

Определение

Внимание!

Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.

Создает сертификат X.509v3 из указанного подписанного файла PKCS7.

C#
public static System.Security.Cryptography.X509Certificates.X509Certificate CreateFromCertFile(string filename);
C#
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static System.Security.Cryptography.X509Certificates.X509Certificate CreateFromCertFile(string filename);
C#
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Obsolete("Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.", DiagnosticId="SYSLIB0057", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static System.Security.Cryptography.X509Certificates.X509Certificate CreateFromCertFile(string filename);

Параметры

filename
String

Путь к подписанному PKCS7-файлу, из которого создается сертификат X.509.

Возвращаемое значение

Созданный сертификат X.509.

Атрибуты

Исключения

Параметр filenamenull.

Примеры

В следующем примере создается X509Certificate из указанного файла сертификации.

C#
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);
    }
}

Комментарии

ASN.1 DER — это единственный формат сертификата, поддерживаемый этим классом.

Примечание

Файл сертификата не ограничен .cer файлами. Любой подписанный PKCS7-файл можно использовать, включая подписанный PFX-файл Authenticode.

Применяется к