语言

X509Certificate2.Import 方法

定义

使用 X509Certificate2 提供的证书信息填充对象。

重载

名称 说明
Import(String, SecureString, X509KeyStorageFlags)
已过时.
已过时.

X509Certificate2使用证书文件、密码和密钥存储标志中的信息填充对象。

Import(Byte[], String, X509KeyStorageFlags)
已过时.
已过时.

X509Certificate2使用字节数组中的数据、密码和标志填充对象,以确定如何导入私钥。

Import(String, String, X509KeyStorageFlags)
已过时.
已过时.

X509Certificate2使用证书文件、密码和X509KeyStorageFlags值中的信息填充对象。

Import(String)
已过时.
已过时.

X509Certificate2使用证书文件中的信息填充对象。

Import(Byte[])
已过时.
已过时.

X509Certificate2使用字节数组中的数据填充对象。

Import(Byte[], SecureString, X509KeyStorageFlags)
已过时.
已过时.

X509Certificate2使用字节数组、密码和密钥存储标志中的数据填充对象。

Import(String, SecureString, X509KeyStorageFlags)

Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs

注意

X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.

注意

X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.

重要

此 API 不符合 CLS。

X509Certificate2使用证书文件、密码和密钥存储标志中的信息填充对象。

public:
 override void Import(System::String ^ fileName, System::Security::SecureString ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
[System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public override void Import(string fileName, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
public override void Import(string fileName, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
[System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public override void Import(string fileName, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
public override void Import(string fileName, System.Security.SecureString password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
public override void Import(string fileName, System.Security.SecureString password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[<System.CLSCompliant(false)>]
[<System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
override this.Import : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
[<System.CLSCompliant(false)>]
override this.Import : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
[<System.CLSCompliant(false)>]
[<System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
override this.Import : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
override this.Import : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
Public Overrides Sub Import (fileName As String, password As SecureString, keyStorageFlags As X509KeyStorageFlags)

参数

fileName
String

证书文件的名称。

password
SecureString

访问 X.509 证书数据所需的密码。

keyStorageFlags
X509KeyStorageFlags

用于控制证书导入位置以及如何导入证书的枚举值的按位组合。

特性

注解

安全说明 从不对源代码中的密码进行硬编码。 可以使用 Ildasm.exe(IL 反汇编程序)、十六进制编辑器或直接在文本编辑器(如 Notepad.exe)中打开程序集,从程序集中检索硬编码的密码。

适用于

Import(Byte[], String, X509KeyStorageFlags)

Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs

注意

X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.

注意

X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.

X509Certificate2使用字节数组中的数据、密码和标志填充对象,以确定如何导入私钥。

public:
 override void Import(cli::array <System::Byte> ^ rawData, System::String ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);
[System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public override void Import(byte[] rawData, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
public override void Import(byte[] rawData, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public override void Import(byte[] rawData, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
public override void Import(byte[] rawData, string password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[<System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
override this.Import : byte[] * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
override this.Import : byte[] * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
[<System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
override this.Import : byte[] * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
Public Overrides Sub Import (rawData As Byte(), password As String, keyStorageFlags As X509KeyStorageFlags)

参数

rawData
Byte[]

包含 X.509 证书中的数据的字节数组。

password
String

访问 X.509 证书数据所需的密码。

keyStorageFlags
X509KeyStorageFlags

用于控制证书导入位置以及如何导入证书的枚举值的按位组合。

特性

示例

下面的代码示例创建一个命令行可执行文件,该可执行文件将证书文件作为参数,并将各种证书属性输出到控制台。

using System;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.IO;
using System.Security.Cryptography.X509Certificates;

class CertInfo
{
    //Reads a file.
    internal static byte[] ReadFile (string fileName)
    {
        FileStream f = new FileStream(fileName, FileMode.Open, FileAccess.Read);
        int size = (int)f.Length;
        byte[] data = new byte[size];
        size = f.Read(data, 0, size);
        f.Close();
        return data;
    }
    //Main method begins here.
    static void Main(string[] args)
    {
        //Test for correct number of arguments.
        if (args.Length < 1)
        {
            Console.WriteLine("Usage: CertInfo <filename>");
            return;
        }
        try
        {
            byte[] rawData = ReadFile(args[0]);
            //Create X509Certificate2 object from .cer file.
            X509Certificate2 x509 = new X509Certificate2(rawData);

            //Print to console information contained in the certificate.
            Console.WriteLine("{0}Subject: {1}{0}", Environment.NewLine, x509.Subject);
            Console.WriteLine("{0}Issuer: {1}{0}", Environment.NewLine, x509.Issuer);
            Console.WriteLine("{0}Version: {1}{0}", Environment.NewLine, x509.Version);
            Console.WriteLine("{0}Valid Date: {1}{0}", Environment.NewLine, x509.NotBefore);
            Console.WriteLine("{0}Expiry Date: {1}{0}", Environment.NewLine, x509.NotAfter);
            Console.WriteLine("{0}Thumbprint: {1}{0}", Environment.NewLine, x509.Thumbprint);
            Console.WriteLine("{0}Serial Number: {1}{0}", Environment.NewLine, x509.SerialNumber);
            Console.WriteLine("{0}Friendly Name: {1}{0}", Environment.NewLine, x509.PublicKey.Oid.FriendlyName);
            Console.WriteLine("{0}Public Key Format: {1}{0}", Environment.NewLine, x509.PublicKey.EncodedKeyValue.Format(true));
            Console.WriteLine("{0}Raw Data Length: {1}{0}", Environment.NewLine, x509.RawData.Length);
            Console.WriteLine("{0}Certificate to string: {1}{0}", Environment.NewLine, x509.ToString(true));
            Console.WriteLine("{0}Certificate to XML String: {1}{0}", Environment.NewLine, x509.PublicKey.Key.ToXmlString(false));

            //Add the certificate to a X509Store.
            X509Store store = new X509Store();
            store.Open(OpenFlags.MaxAllowed);
            store.Add(x509);
            store.Close();
        }
        catch (DirectoryNotFoundException)
        {
               Console.WriteLine("Error: The directory specified could not be found.");
        }
        catch (IOException)
        {
            Console.WriteLine("Error: A file in the directory could not be accessed.");
        }
        catch (NullReferenceException)
        {
            Console.WriteLine("File must be a .cer file. Program does not have access to that type of file.");
        }
    }
}
Imports System.Security.Cryptography
Imports System.Security.Permissions
Imports System.IO
Imports System.Security.Cryptography.X509Certificates

Class CertInfo

    'Reads a file.
    Friend Shared Function ReadFile(ByVal fileName As String) As Byte()
        Dim f As New FileStream(fileName, FileMode.Open, FileAccess.Read)
        Dim size As Integer = Fix(f.Length)
        Dim data(size - 1) As Byte
        size = f.Read(data, 0, size)
        f.Close()
        Return data

    End Function 

    <SecurityPermission(SecurityAction.LinkDemand, Unrestricted:=True)> _
    Shared Sub Main(ByVal args() As String)
        'Test for correct number of arguments.
        If args.Length < 1 Then
            Console.WriteLine("Usage: CertInfo <filename>")
            Return
        End If
        Try
            Dim x509 As New X509Certificate2()
            'Create X509Certificate2 object from .cer file.
            Dim rawData As Byte() = ReadFile(args(0))
            
            x509.Import(rawData)

            'Print to console information contained in the certificate.
            Console.WriteLine("{0}Subject: {1}{0}", Environment.NewLine, x509.Subject)
            Console.WriteLine("{0}Issuer: {1}{0}", Environment.NewLine, x509.Issuer)
            Console.WriteLine("{0}Version: {1}{0}", Environment.NewLine, x509.Version)
            Console.WriteLine("{0}Valid Date: {1}{0}", Environment.NewLine, x509.NotBefore)
            Console.WriteLine("{0}Expiry Date: {1}{0}", Environment.NewLine, x509.NotAfter)
            Console.WriteLine("{0}Thumbprint: {1}{0}", Environment.NewLine, x509.Thumbprint)
            Console.WriteLine("{0}Serial Number: {1}{0}", Environment.NewLine, x509.SerialNumber)
            Console.WriteLine("{0}Friendly Name: {1}{0}", Environment.NewLine, x509.PublicKey.Oid.FriendlyName)
            Console.WriteLine("{0}Public Key Format: {1}{0}", Environment.NewLine, x509.PublicKey.EncodedKeyValue.Format(True))
            Console.WriteLine("{0}Raw Data Length: {1}{0}", Environment.NewLine, x509.RawData.Length)
            Console.WriteLine("{0}Certificate to string: {1}{0}", Environment.NewLine, x509.ToString(True))

            Console.WriteLine("{0}Certificate to XML String: {1}{0}", Environment.NewLine, x509.PublicKey.Key.ToXmlString(False))

            'Add the certificate to a X509Store.
            Dim store As New X509Store()
            store.Open(OpenFlags.MaxAllowed)
            store.Add(x509)
            store.Close()

        Catch dnfExcept As DirectoryNotFoundException
            Console.WriteLine("Error: The directory specified could not be found.")
        Catch ioExpcept As IOException
            Console.WriteLine("Error: A file in the directory could not be accessed.")
        Catch nrExcept As NullReferenceException
            Console.WriteLine("File must be a .cer file. Program does not have access to that type of file.")
        End Try

    End Sub
End Class

注解

此方法可用于使用字节数组表示的证书的密码填充 X509Certificate2 对象。 X509KeyStorageFlags该值可用于控制私钥的位置以及如何导入私钥。

此方法接受字节数组,可用于 PEM 编码或 DER 编码 X.509 证书或 PFX/PKCS12 证书等证书类型。 请注意,PFX/PKCS12 证书可以包含多个证书。 在这种情况下,将使用与私钥关联的第一个证书;如果未找到私钥,则使用第一个证书。

Important

从不对源代码中的密码进行硬编码。 可以使用 Ildasm.exe(IL 反汇编程序)、十六进制编辑器或直接在文本编辑器(如 Notepad.exe)中打开程序集,从程序集中检索硬编码的密码。

适用于

Import(String, String, X509KeyStorageFlags)

Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs

注意

X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.

注意

X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.

X509Certificate2使用证书文件、密码和X509KeyStorageFlags值中的信息填充对象。

public:
 override void Import(System::String ^ fileName, System::String ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);
[System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public override void Import(string fileName, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
public override void Import(string fileName, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public override void Import(string fileName, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
public override void Import(string fileName, string password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[<System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
override this.Import : string * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
override this.Import : string * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
[<System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
override this.Import : string * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
Public Overrides Sub Import (fileName As String, password As String, keyStorageFlags As X509KeyStorageFlags)

参数

fileName
String

证书文件的名称。

password
String

访问 X.509 证书数据所需的密码。

keyStorageFlags
X509KeyStorageFlags

用于控制证书导入位置以及如何导入证书的枚举值的按位组合。

特性

注解

此方法可以使用证书文件、密码和X509Certificate2值中的信息填充X509KeyStorageFlags对象。

Important

从不对源代码中的密码进行硬编码。 可以使用 Ildasm.exe(IL 反汇编程序)、十六进制编辑器或直接在文本编辑器(如 Notepad.exe)中打开程序集,从程序集中检索硬编码的密码。

适用于

Import(String)

Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs

注意

X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.

注意

X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.

X509Certificate2使用证书文件中的信息填充对象。

public:
 override void Import(System::String ^ fileName);
[System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public override void Import(string fileName);
public override void Import(string fileName);
[System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public override void Import(string fileName);
[<System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
override this.Import : string -> unit
override this.Import : string -> unit
[<System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
override this.Import : string -> unit
Public Overrides Sub Import (fileName As String)

参数

fileName
String

证书的名称。

特性

注解

此方法使用证书文件(例如具有.cer扩展名的文件)来表示 X.509 证书,并使用文件包含的证书填充 X509Certificate2 对象。

此方法可以与多种证书类型一起使用,包括 PEM 编码或 DER 编码的 X.509 证书、PFX/PKCS12 证书和签名者证书(如 Authenticode)。 请注意,PFX/PKCS12 证书可以包含多个证书。 在这种情况下,将使用与私钥关联的第一个证书;如果未找到私钥,则使用第一个证书。

适用于

Import(Byte[])

Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs

注意

X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.

注意

X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.

X509Certificate2使用字节数组中的数据填充对象。

public:
 override void Import(cli::array <System::Byte> ^ rawData);
[System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public override void Import(byte[] rawData);
public override void Import(byte[] rawData);
[System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public override void Import(byte[] rawData);
[<System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
override this.Import : byte[] -> unit
override this.Import : byte[] -> unit
[<System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
override this.Import : byte[] -> unit
Public Overrides Sub Import (rawData As Byte())

参数

rawData
Byte[]

包含 X.509 证书中的数据的字节数组。

特性

注解

此方法可用于获取 X.509 证书的原始字节数组,并使用其关联的值填充 X509Certificate2 对象。

由于此方法仅接受字节数组,因此只能用于不需要密码的证书类型,包括 PEM 编码或 DER 编码的 X.509 证书或 PFX/PKCS12 证书。 请注意,PFX/PKCS12 证书可以包含多个证书。 在这种情况下,将使用与私钥关联的第一个证书;如果未找到私钥,则使用第一个证书。

适用于

Import(Byte[], SecureString, X509KeyStorageFlags)

Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs
Source:
X509Certificate2.cs

注意

X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.

注意

X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.

重要

此 API 不符合 CLS。

X509Certificate2使用字节数组、密码和密钥存储标志中的数据填充对象。

public:
 override void Import(cli::array <System::Byte> ^ rawData, System::Security::SecureString ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
[System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public override void Import(byte[] rawData, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
public override void Import(byte[] rawData, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
[System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public override void Import(byte[] rawData, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
public override void Import(byte[] rawData, System.Security.SecureString password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
public override void Import(byte[] rawData, System.Security.SecureString password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[<System.CLSCompliant(false)>]
[<System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
override this.Import : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
[<System.CLSCompliant(false)>]
override this.Import : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
[<System.CLSCompliant(false)>]
[<System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
override this.Import : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
override this.Import : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
Public Overrides Sub Import (rawData As Byte(), password As SecureString, keyStorageFlags As X509KeyStorageFlags)

参数

rawData
Byte[]

包含 X.509 证书中的数据的字节数组。

password
SecureString

访问 X.509 证书数据所需的密码。

keyStorageFlags
X509KeyStorageFlags

用于控制证书导入位置以及如何导入证书的枚举值的按位组合。

特性

注解

可以将此方法用于证书类型,例如 PEM 编码或 DER 编码的 X.509 证书或 PFX/PKCS12 证书。 请注意,PFX/PKCS12 证书可以包含多个证书。 在这种情况下,将使用与私钥关联的第一个证书;如果未找到私钥,则使用第一个证书。

Important

从不对源代码中的密码进行硬编码。 可以使用 Ildasm.exe(IL 反汇编程序)、十六进制编辑器或直接在文本编辑器(如 Notepad.exe)中打开程序集,从程序集中检索硬编码的密码。

适用于