X509Certificate2 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 X509Certificate2 类的新实例。
重载
X509Certificate2()
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate.
注意
X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.
初始化 X509Certificate2 类的新实例。
public:
 X509Certificate2();public X509Certificate2 ();[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 X509Certificate2 ();[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}")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 ();[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public X509Certificate2 ();Public Sub New ()- 属性
示例
下面的代码示例打开当前用户证书存储,仅选择活动证书,然后允许用户选择一个或多个证书。 然后,该示例将证书信息写入控制台。
#using <System.dll>
#using <System.Security.dll>
using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Security::Permissions;
using namespace System::IO;
using namespace System::Security::Cryptography::X509Certificates;
int main()
{
   try
   {
      X509Store ^ store = gcnew X509Store( "MY",StoreLocation::CurrentUser );
      store->Open( static_cast<OpenFlags>(OpenFlags::ReadOnly | OpenFlags::OpenExistingOnly) );
      X509Certificate2Collection ^ collection = dynamic_cast<X509Certificate2Collection^>(store->Certificates);
      X509Certificate2Collection ^ fcollection = dynamic_cast<X509Certificate2Collection^>(collection->Find( X509FindType::FindByTimeValid, DateTime::Now, false ));
      X509Certificate2Collection ^ scollection = X509Certificate2UI::SelectFromCollection(fcollection, "Test Certificate Select","Select a certificate from the following list to get information on that certificate",X509SelectionFlag::MultiSelection);
      Console::WriteLine( "Number of certificates: {0}{1}", scollection->Count, Environment::NewLine );
      System::Collections::IEnumerator^ myEnum = scollection->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         X509Certificate2 ^ x509 = safe_cast<X509Certificate2 ^>(myEnum->Current);
         array<Byte>^rawdata = x509->RawData;
         Console::WriteLine( "Content Type: {0}{1}", X509Certificate2::GetCertContentType( rawdata ), Environment::NewLine );
         Console::WriteLine( "Friendly Name: {0}{1}", x509->FriendlyName, Environment::NewLine );
         Console::WriteLine( "Certificate Verified?: {0}{1}", x509->Verify(), Environment::NewLine );
         Console::WriteLine( "Simple Name: {0}{1}", x509->GetNameInfo( X509NameType::SimpleName, true ), Environment::NewLine );
         Console::WriteLine( "Signature Algorithm: {0}{1}", x509->SignatureAlgorithm->FriendlyName, Environment::NewLine );
         Console::WriteLine( "Private Key: {0}{1}", x509->PrivateKey->ToXmlString( false ), Environment::NewLine );
         Console::WriteLine( "Public Key: {0}{1}", x509->PublicKey->Key->ToXmlString( false ), Environment::NewLine );
         Console::WriteLine( "Certificate Archived?: {0}{1}", x509->Archived, Environment::NewLine );
         Console::WriteLine( "Length of Raw Data: {0}{1}", x509->RawData->Length, Environment::NewLine );
         x509->Reset();
      }
      store->Close();
   }
   catch ( CryptographicException^ ) 
   {
      Console::WriteLine( "Information could not be written out for this certificate." );
   }
}
using System;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.IO;
using System.Security.Cryptography.X509Certificates;
class CertSelect
{
    static void Main()
    {
        X509Store store = new X509Store("MY",StoreLocation.CurrentUser);
        store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
        X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
        X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByTimeValid,DateTime.Now,false);
        X509Certificate2Collection scollection = X509Certificate2UI.SelectFromCollection(fcollection, "Test Certificate Select","Select a certificate from the following list to get information on that certificate",X509SelectionFlag.MultiSelection);
        Console.WriteLine("Number of certificates: {0}{1}",scollection.Count,Environment.NewLine);
        foreach (X509Certificate2 x509 in scollection)
        {
            try
            {
                byte[] rawdata = x509.RawData;
                Console.WriteLine("Content Type: {0}{1}",X509Certificate2.GetCertContentType(rawdata),Environment.NewLine);
                Console.WriteLine("Friendly Name: {0}{1}",x509.FriendlyName,Environment.NewLine);
                Console.WriteLine("Certificate Verified?: {0}{1}",x509.Verify(),Environment.NewLine);
                Console.WriteLine("Simple Name: {0}{1}",x509.GetNameInfo(X509NameType.SimpleName,true),Environment.NewLine);
                Console.WriteLine("Signature Algorithm: {0}{1}",x509.SignatureAlgorithm.FriendlyName,Environment.NewLine);
                Console.WriteLine("Public Key: {0}{1}",x509.PublicKey.Key.ToXmlString(false),Environment.NewLine);
                Console.WriteLine("Certificate Archived?: {0}{1}",x509.Archived,Environment.NewLine);
                Console.WriteLine("Length of Raw Data: {0}{1}",x509.RawData.Length,Environment.NewLine);
                X509Certificate2UI.DisplayCertificate(x509);
                x509.Reset();
            }
            catch (CryptographicException)
            {
                Console.WriteLine("Information could not be written out for this certificate.");
            }
        }
        store.Close();
    }
}
Imports System.Security.Cryptography
Imports System.Security.Permissions
Imports System.IO
Imports System.Security.Cryptography.X509Certificates
Class CertSelect
    Shared Sub Main()
        Dim store As New X509Store("MY", StoreLocation.CurrentUser)
        store.Open(OpenFlags.ReadOnly Or OpenFlags.OpenExistingOnly)
        Dim collection As X509Certificate2Collection = CType(store.Certificates, X509Certificate2Collection)
        Dim fcollection As X509Certificate2Collection = CType(collection.Find(X509FindType.FindByTimeValid, DateTime.Now, False), X509Certificate2Collection)
        Dim scollection As X509Certificate2Collection = X509Certificate2UI.SelectFromCollection(fcollection, "Test Certificate Select", "Select a certificate from the following list to get information on that certificate", X509SelectionFlag.MultiSelection)
        Console.WriteLine("Number of certificates: {0}{1}", scollection.Count, Environment.NewLine)
         
        For Each x509 As X509Certificate2 In scollection
            Try
                Dim rawdata As Byte() = x509.RawData
                Console.WriteLine("Content Type: {0}{1}", X509Certificate2.GetCertContentType(rawdata), Environment.NewLine)
                Console.WriteLine("Friendly Name: {0}{1}", x509.FriendlyName, Environment.NewLine)
                Console.WriteLine("Certificate Verified?: {0}{1}", x509.Verify(), Environment.NewLine)
                Console.WriteLine("Simple Name: {0}{1}", x509.GetNameInfo(X509NameType.SimpleName, True), Environment.NewLine)
                Console.WriteLine("Signature Algorithm: {0}{1}", x509.SignatureAlgorithm.FriendlyName, Environment.NewLine)
                Console.WriteLine("Public Key: {0}{1}", x509.PublicKey.Key.ToXmlString(False), Environment.NewLine)
                Console.WriteLine("Certificate Archived?: {0}{1}", x509.Archived, Environment.NewLine)
                Console.WriteLine("Length of Raw Data: {0}{1}", x509.RawData.Length, Environment.NewLine)
                X509Certificate2UI.DisplayCertificate(x509)
                x509.Reset()         
             Catch cExcept As CryptographicException
                 Console.WriteLine("Information could not be written out for this certificate.")
             End Try
        Next x509
        store.Close()
    End Sub
End Class
注解
此构造函数创建一个空 X509Certificate2 对象,这与此类的其他构造函数不同,这些构造函数使用字节数组、指针或证书文件中的证书信息。
适用于
X509Certificate2(String, String, X509KeyStorageFlags)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
使用一个证书文件名、一个用于访问该证书的密码和一个密钥存储标志初始化 X509Certificate2 类的新实例。
public:
 X509Certificate2(System::String ^ fileName, System::String ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);public X509Certificate2 (string fileName, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (string fileName, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);[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 X509Certificate2 (string fileName, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);public X509Certificate2 (string fileName, string password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2[<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}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (fileName As String, password As String, keyStorageFlags As X509KeyStorageFlags)参数
- fileName
- String
一个证书文件的名称。
- password
- String
访问 X.509 证书数据所需的密码。
- keyStorageFlags
- X509KeyStorageFlags
一个枚举值的按位组合,这些值控制在何处以及如何导入证书。
- 属性
例外
注解
此构造函数使用证书文件名、访问证书所需的密码和密钥存储标志创建新 X509Certificate2 对象。
重要
切勿在源代码中对密码进行硬编码。 可以使用 Ildasm.exe (IL 反汇编程序) 、十六进制编辑器或直接在文本编辑器(如 Notepad.exe)中打开程序集来检索硬编码密码。
如果通过为 fileName指定 PKCS7 签名文件存储来创建X509Certificate2证书,X509Certificate2则会为签名存储的证书而不是存储区中的任何证书创建 。
适用于
X509Certificate2(String, SecureString, X509KeyStorageFlags)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
重要
此 API 不符合 CLS。
使用一个证书文件名、一个密码和一个密钥存储标志初始化 X509Certificate2 类的新实例。
public:
 X509Certificate2(System::String ^ fileName, System::Security::SecureString ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);[System.CLSCompliant(false)]
public X509Certificate2 (string fileName, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);[System.CLSCompliant(false)]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (string fileName, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);[System.CLSCompliant(false)]
[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 X509Certificate2 (string fileName, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);[System.CLSCompliant(false)]
public X509Certificate2 (string fileName, System.Security.SecureString password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);public X509Certificate2 (string fileName, System.Security.SecureString password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);[<System.CLSCompliant(false)>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.CLSCompliant(false)>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.CLSCompliant(false)>]
[<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}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (fileName As String, password As SecureString, keyStorageFlags As X509KeyStorageFlags)参数
- fileName
- String
一个证书文件的名称。
- password
- SecureString
访问 X.509 证书数据所需的密码。
- keyStorageFlags
- X509KeyStorageFlags
一个枚举值的按位组合,这些值控制在何处以及如何导入证书。
- 属性
例外
注解
如果通过为 fileName指定 PKCS7 签名文件存储来创建X509Certificate证书,X509Certificate则会为签名存储的证书而不是存储区中的任何证书创建 。
适用于
X509Certificate2(String, ReadOnlySpan<Char>, X509KeyStorageFlags)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
使用一个证书文件名、一个密码和一个密钥存储标志初始化 X509Certificate2 类的新实例。
public X509Certificate2 (string fileName, ReadOnlySpan<char> password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags = System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.DefaultKeySet);[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (string fileName, ReadOnlySpan<char> password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags = System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.DefaultKeySet);[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 X509Certificate2 (string fileName, ReadOnlySpan<char> password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags = System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.DefaultKeySet);new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * ReadOnlySpan<char> * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * ReadOnlySpan<char> * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2[<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}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * ReadOnlySpan<char> * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (fileName As String, password As ReadOnlySpan(Of Char), Optional keyStorageFlags As X509KeyStorageFlags = System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.DefaultKeySet)参数
- fileName
- String
一个证书文件的名称。
- password
- ReadOnlySpan<Char>
访问 X.509 证书数据所需的密码。
- keyStorageFlags
- X509KeyStorageFlags
一个枚举值的按位组合,这些值控制在何处以及如何导入证书。
- 属性
例外
注解
重要
切勿在源代码中对密码进行硬编码。 可以使用 Ildasm.exe (IL 反汇编程序) 、十六进制编辑器或直接在文本编辑器(如 Notepad.exe)中打开程序集来检索硬编码密码。
如果通过为 fileName指定 PKCS7 签名文件存储来创建X509Certificate2证书,X509Certificate2则会为签名存储的证书而不是存储区中的任何证书创建 。
适用于
X509Certificate2(Byte[], String, X509KeyStorageFlags)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
使用一个字节数组、一个密码和一个密钥存储标志初始化 X509Certificate2 类的新实例。
public:
 X509Certificate2(cli::array <System::Byte> ^ rawData, System::String ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);public X509Certificate2 (byte[] rawData, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (byte[] rawData, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);[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 X509Certificate2 (byte[] rawData, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);public X509Certificate2 (byte[] rawData, string password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2[<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}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (rawData As Byte(), password As String, keyStorageFlags As X509KeyStorageFlags)参数
- rawData
- Byte[]
一个包含 X.509 证书数据的字节数组。
- password
- String
访问 X.509 证书数据所需的密码。
- keyStorageFlags
- X509KeyStorageFlags
一个枚举值的按位组合,这些值控制在何处以及如何导入证书。
- 属性
例外
注解
此构造函数使用字节数组、访问证书数据所需的密码和密钥存储标志创建新 X509Certificate2 对象。 它与 PKCS12 (PFX) 包含证书私钥的文件一起使用。 使用正确的密码调用此构造函数会解密私钥,并将其保存到 Microsoft 加密 API 加密服务提供程序 (CSP) 。
重要
切勿在源代码中对密码进行硬编码。 可以使用 Ildasm.exe (IL 反汇编程序) 、十六进制编辑器或直接在文本编辑器(如 Notepad.exe)中打开程序集来检索硬编码密码。
如果通过为 rawData指定 PKCS7 签名文件存储来创建X509Certificate2证书,X509Certificate2则会为签名存储的证书而不是存储区中的任何证书创建 。
适用于
X509Certificate2(Byte[], SecureString, X509KeyStorageFlags)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
重要
此 API 不符合 CLS。
使用一个字节数组、一个密码和一个密钥存储标志初始化 X509Certificate2 类的新实例。
public:
 X509Certificate2(cli::array <System::Byte> ^ rawData, System::Security::SecureString ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);[System.CLSCompliant(false)]
public X509Certificate2 (byte[] rawData, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);[System.CLSCompliant(false)]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (byte[] rawData, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);[System.CLSCompliant(false)]
[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 X509Certificate2 (byte[] rawData, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);[System.CLSCompliant(false)]
public X509Certificate2 (byte[] rawData, System.Security.SecureString password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);public X509Certificate2 (byte[] rawData, System.Security.SecureString password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);[<System.CLSCompliant(false)>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.CLSCompliant(false)>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.CLSCompliant(false)>]
[<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}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (rawData As Byte(), password As SecureString, keyStorageFlags As X509KeyStorageFlags)参数
- rawData
- Byte[]
包含 X.509 证书数据的字节数组。
- password
- SecureString
访问 X.509 证书数据所需的密码。
- keyStorageFlags
- X509KeyStorageFlags
一个枚举值的按位组合,这些值控制在何处以及如何导入证书。
- 属性
例外
注解
此构造函数与 PKCS12 (PFX) 包含证书私钥的文件一起使用。 使用正确的密码调用此构造函数会解密私钥,并将其保存到 Microsoft 加密 API 加密服务提供程序 (CSP) 。
重要
切勿在源代码中对密码进行硬编码。 可以使用 Ildasm.exe (IL 反汇编程序) (十六进制编辑器)或直接在文本编辑器(如 Notepad.exe)中打开程序集来检索硬编码密码。
如果通过为 指定 PKCS7 签名文件存储来创建X509Certificate证书,X509Certificate则会为rawData对存储区进行签名的证书创建 ,而不是为存储中的任何证书创建 。
适用于
X509Certificate2(String, String)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
使用一个证书文件名和一个用于访问该证书的密码初始化 X509Certificate2 类的新实例。
public:
 X509Certificate2(System::String ^ fileName, System::String ^ password);public X509Certificate2 (string fileName, string? password);[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (string fileName, string? password);[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 X509Certificate2 (string fileName, string? password);public X509Certificate2 (string fileName, string password);new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * string -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * string -> System.Security.Cryptography.X509Certificates.X509Certificate2[<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}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * string -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (fileName As String, password As String)参数
- fileName
- String
一个证书文件的名称。
- password
- String
访问 X.509 证书数据所需的密码。
- 属性
例外
注解
此构造函数使用访问证书所需的证书文件名和密码创建新的 X509Certificate2 对象。 它与 PKCS12 (PFX) 包含证书私钥的文件一起使用。 使用正确的密码调用此构造函数会解密私钥并将其保存到密钥容器。
重要
切勿在源代码中对密码进行硬编码。 可以使用 Ildasm.exe (IL 反汇编程序) (十六进制编辑器)或直接在文本编辑器(如 Notepad.exe)中打开程序集来检索硬编码密码。
如果通过为 指定 PKCS7 签名文件存储来创建X509Certificate2证书,X509Certificate2则会为fileName对存储区进行签名的证书创建 ,而不是为存储中的任何证书创建 。
适用于
X509Certificate2(String, SecureString)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
重要
此 API 不符合 CLS。
使用一个证书文件名和一个密码初始化 X509Certificate2 类的新实例。
public:
 X509Certificate2(System::String ^ fileName, System::Security::SecureString ^ password);[System.CLSCompliant(false)]
public X509Certificate2 (string fileName, System.Security.SecureString? password);[System.CLSCompliant(false)]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (string fileName, System.Security.SecureString? password);[System.CLSCompliant(false)]
[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 X509Certificate2 (string fileName, System.Security.SecureString? password);[System.CLSCompliant(false)]
public X509Certificate2 (string fileName, System.Security.SecureString password);public X509Certificate2 (string fileName, System.Security.SecureString password);[<System.CLSCompliant(false)>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.CLSCompliant(false)>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.CLSCompliant(false)>]
[<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}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate2new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (fileName As String, password As SecureString)参数
- fileName
- String
一个证书文件的名称。
- password
- SecureString
访问 X.509 证书数据所需的密码。
- 属性
例外
注解
此构造函数与 PKCS12 (PFX) 包含证书私钥的文件一起使用。 使用正确的密码调用此构造函数会解密私钥并将其保存到密钥容器。
重要
切勿在源代码中对密码进行硬编码。 可以使用 Ildasm.exe (IL 反汇编程序) (十六进制编辑器)或直接在文本编辑器(如 Notepad.exe)中打开程序集来检索硬编码密码。
如果通过为 指定 PKCS7 签名文件存储来创建X509Certificate证书,X509Certificate则会为fileName对存储区进行签名的证书创建 ,而不是为存储中的任何证书创建 。
适用于
X509Certificate2(ReadOnlySpan<Byte>, ReadOnlySpan<Char>, X509KeyStorageFlags)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
使用证书数据、密码和密钥存储标志初始化 X509Certificate2 类的新实例。
public X509Certificate2 (ReadOnlySpan<byte> rawData, ReadOnlySpan<char> password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags = System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.DefaultKeySet);[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (ReadOnlySpan<byte> rawData, ReadOnlySpan<char> password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags = System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.DefaultKeySet);[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 X509Certificate2 (ReadOnlySpan<byte> rawData, ReadOnlySpan<char> password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags = System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.DefaultKeySet);new System.Security.Cryptography.X509Certificates.X509Certificate2 : ReadOnlySpan<byte> * ReadOnlySpan<char> * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : ReadOnlySpan<byte> * ReadOnlySpan<char> * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2[<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}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : ReadOnlySpan<byte> * ReadOnlySpan<char> * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (rawData As ReadOnlySpan(Of Byte), password As ReadOnlySpan(Of Char), Optional keyStorageFlags As X509KeyStorageFlags = System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.DefaultKeySet)参数
- rawData
- ReadOnlySpan<Byte>
要处理的证书数据。
- password
- ReadOnlySpan<Char>
访问证书数据所需的密码。
- keyStorageFlags
- X509KeyStorageFlags
一个枚举值的按位组合,这些值控制在何处以及如何导入证书。
- 属性
例外
发生了与证书有关的错误。
适用于
X509Certificate2(Byte[], String)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
使用一个字节数组和一个密码初始化 X509Certificate2 类的新实例。
public:
 X509Certificate2(cli::array <System::Byte> ^ rawData, System::String ^ password);public X509Certificate2 (byte[] rawData, string? password);[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (byte[] rawData, string? password);[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 X509Certificate2 (byte[] rawData, string? password);public X509Certificate2 (byte[] rawData, string password);new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * string -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * string -> System.Security.Cryptography.X509Certificates.X509Certificate2[<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}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * string -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (rawData As Byte(), password As String)参数
- rawData
- Byte[]
一个包含 X.509 证书数据的字节数组。
- password
- String
访问 X.509 证书数据所需的密码。
- 属性
例外
注解
此构造函数使用访问证书数据所需的字节数组和密码创建新的 X509Certificate2 对象。 它与 PKCS12 (PFX) 包含证书私钥的文件一起使用。 使用正确的密码调用此构造函数会解密私钥并将其保存到密钥容器。
重要
切勿在源代码中对密码进行硬编码。 可以使用 Ildasm.exe (IL 反汇编程序) (十六进制编辑器)或直接在文本编辑器(如 Notepad.exe)中打开程序集来检索硬编码密码。
如果通过为 指定 PKCS7 签名文件存储来创建X509Certificate2证书,X509Certificate2则会为rawData对存储区进行签名的证书创建 ,而不是为存储中的任何证书创建 。
适用于
X509Certificate2(Byte[], SecureString)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
重要
此 API 不符合 CLS。
使用一个字节数组和一个密码初始化 X509Certificate2 类的新实例。
public:
 X509Certificate2(cli::array <System::Byte> ^ rawData, System::Security::SecureString ^ password);[System.CLSCompliant(false)]
public X509Certificate2 (byte[] rawData, System.Security.SecureString? password);[System.CLSCompliant(false)]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (byte[] rawData, System.Security.SecureString? password);[System.CLSCompliant(false)]
[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 X509Certificate2 (byte[] rawData, System.Security.SecureString? password);[System.CLSCompliant(false)]
public X509Certificate2 (byte[] rawData, System.Security.SecureString password);public X509Certificate2 (byte[] rawData, System.Security.SecureString password);[<System.CLSCompliant(false)>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.CLSCompliant(false)>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.CLSCompliant(false)>]
[<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}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate2new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (rawData As Byte(), password As SecureString)参数
- rawData
- Byte[]
包含 X.509 证书数据的字节数组。
- password
- SecureString
访问 X.509 证书数据所需的密码。
- 属性
例外
注解
此构造函数与 PKCS12 (PFX) 包含证书私钥的文件一起使用。 使用正确的密码调用此构造函数会解密私钥并将其保存到密钥容器。
重要
切勿在源代码中对密码进行硬编码。 可以使用 Ildasm.exe (IL 反汇编程序) (十六进制编辑器)或直接在文本编辑器(如 Notepad.exe)中打开程序集来检索硬编码密码。
如果通过为 指定 PKCS7 签名文件存储来创建X509Certificate证书,X509Certificate则会为rawData对存储区进行签名的证书创建 ,而不是为存储中的任何证书创建 。
适用于
X509Certificate2(String)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
使用证书文件名初始化 X509Certificate2 类的新实例。
public:
 X509Certificate2(System::String ^ fileName);public X509Certificate2 (string fileName);[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (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 X509Certificate2 (string fileName);new System.Security.Cryptography.X509Certificates.X509Certificate2 : string -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string -> System.Security.Cryptography.X509Certificates.X509Certificate2[<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}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (fileName As String)参数
- fileName
- String
一个证书文件的名称。
- 属性
例外
注解
此构造函数使用证书文件名创建新的 X509Certificate2 对象。 它支持二进制 (DER) 编码或 Base64 编码。
如果通过为 指定 PKCS7 签名文件存储来创建X509Certificate2证书,X509Certificate2则会为fileName对存储区进行签名的证书创建 ,而不是为存储中的任何证书创建 。
适用于
X509Certificate2(X509Certificate)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
使用 X509Certificate 对象初始化 X509Certificate2 类的新实例。
public:
 X509Certificate2(System::Security::Cryptography::X509Certificates::X509Certificate ^ certificate);public X509Certificate2 (System.Security.Cryptography.X509Certificates.X509Certificate certificate);[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (System.Security.Cryptography.X509Certificates.X509Certificate certificate);new System.Security.Cryptography.X509Certificates.X509Certificate2 : System.Security.Cryptography.X509Certificates.X509Certificate -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : System.Security.Cryptography.X509Certificates.X509Certificate -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (certificate As X509Certificate)参数
- certificate
- X509Certificate
一个 X509Certificate 对象。
- 属性
例外
注解
此方法使用 X509Certificate 对象创建 类的新实例X509Certificate2。
适用于
X509Certificate2(SerializationInfo, StreamingContext)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
This API supports obsolete formatter-based serialization. It should not be called or extended by application code.
使用指定的序列化和流上下文信息初始化 X509Certificate2 类的新实例。
protected:
 X509Certificate2(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);protected X509Certificate2 (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected X509Certificate2 (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);new System.Security.Cryptography.X509Certificates.X509Certificate2 : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Cryptography.X509Certificates.X509Certificate2Protected Sub New (info As SerializationInfo, context As StreamingContext)参数
- info
- SerializationInfo
反序列化新的 X509Certificate2 所需的序列化信息。
- context
- StreamingContext
有关要反序列化的流的源的上下文信息。
- 属性
例外
仅限 .NET Core 和 .NET 5 及更高版本:在所有情况下。
适用于
X509Certificate2(ReadOnlySpan<Byte>)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
用证书数据初始化 X509Certificate2 类的新实例。
public:
 X509Certificate2(ReadOnlySpan<System::Byte> rawData);public X509Certificate2 (ReadOnlySpan<byte> rawData);[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (ReadOnlySpan<byte> rawData);[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 X509Certificate2 (ReadOnlySpan<byte> rawData);new System.Security.Cryptography.X509Certificates.X509Certificate2 : ReadOnlySpan<byte> -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : ReadOnlySpan<byte> -> System.Security.Cryptography.X509Certificates.X509Certificate2[<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}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : ReadOnlySpan<byte> -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (rawData As ReadOnlySpan(Of Byte))参数
- rawData
- ReadOnlySpan<Byte>
要处理的证书数据。
- 属性
例外
发生了与证书有关的错误。
适用于
X509Certificate2(IntPtr)
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
使用非托管句柄初始化 X509Certificate2 类的新实例。
public:
 X509Certificate2(IntPtr handle);public X509Certificate2 (IntPtr handle);[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (IntPtr handle);new System.Security.Cryptography.X509Certificates.X509Certificate2 : nativeint -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : nativeint -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (handle As IntPtr)参数
- handle
- 
				
				IntPtr
nativeint 
一个指向非托管代码中的证书上下文的指针。 C 结构称为 PCCERT_CONTEXT。
- 属性
例外
注解
此构造函数使用 Microsoft 加密 API 证书上下文PCCERT_CONTEXT的句柄创建新X509Certificate2对象。 请注意,此构造函数的直接调用方需要非托管代码权限。
重要
构造函数创建证书上下文的副本。 不要假定传递给构造函数的上下文结构有效;它可能已被释放。 可以从 属性获取当前 PCCERT_CONTEXT 结构 Handle 的副本,但它仅在对象的生存期内 X509Certificate2 有效。
适用于
X509Certificate2(Byte[])
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
- Source:
- X509Certificate2.cs
注意
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
使用来自字节数组的信息初始化 X509Certificate2 类的新实例。
public:
 X509Certificate2(cli::array <System::Byte> ^ rawData);public X509Certificate2 (byte[] rawData);[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2 (byte[] rawData);[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 X509Certificate2 (byte[] rawData);new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] -> System.Security.Cryptography.X509Certificates.X509Certificate2[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] -> System.Security.Cryptography.X509Certificates.X509Certificate2[<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}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] -> System.Security.Cryptography.X509Certificates.X509Certificate2Public Sub New (rawData As Byte())参数
- rawData
- Byte[]
一个包含 X.509 证书数据的字节数组。
- 属性
例外
注解
此构造函数使用字节数组中的证书信息创建新 X509Certificate2 对象。 字节数组可以是编码的二进制文件 (DER) 或 Base64 编码的 X.509 数据。 字节数组也可以是 PKCS7 (Authenticode) 签名文件;签名者证书用于创建 对象。
如果通过为 rawData指定 PKCS7 签名文件存储来创建X509Certificate2证书,X509Certificate2则会为签名存储的证书而不是存储区中的任何证书创建 。