X509Certificate.CreateFromCertFile(String) メソッド

定義

注意事項

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

指定した PKCS7 署名済みファイルから X.509v3 証明書を作成します。

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);
[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);
static member CreateFromCertFile : string -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
static member CreateFromCertFile : string -> System.Security.Cryptography.X509Certificates.X509Certificate
[<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}")>]
static member CreateFromCertFile : string -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Shared Function CreateFromCertFile (filename As String) As X509Certificate

パラメーター

filename
String

X.509 証明書の作成元となる PKCS7 署名済みファイルのパス。

戻り値

新しく作成された X.509 証明書。

属性

例外

filename パラメーターは nullです。

次の例では、指定した認定ファイルから X509Certificate を作成します。

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

注釈

ASN.1 DER は、このクラスでサポートされている唯一の証明書形式です。

手記

証明書ファイルは、.cer ファイルに限定されません。 Authenticode 署名付き .pfx ファイルを含め、任意の PKCS7 署名済みファイルを使用できます。

適用対象