語言

X509Certificate2 建構函式

定義

初始化 X509Certificate2 類別的新執行個體。

多載

名稱 Description
X509Certificate2()
已淘汰.
已淘汰.

初始化 X509Certificate2 類別的新執行個體。

X509Certificate2(String, ReadOnlySpan<Char>, X509KeyStorageFlags)
已淘汰.

使用憑證檔案名稱、密碼及金鑰儲存標誌初始化該類別的新 X509Certificate2 實例。

X509Certificate2(ReadOnlySpan<Byte>, ReadOnlySpan<Char>, X509KeyStorageFlags)
已淘汰.

從憑證資料、密碼及金鑰儲存旗標初始化該類別的新實例 X509Certificate2 。

X509Certificate2(Byte[], String, X509KeyStorageFlags)
已淘汰.

使用位元組陣列、密碼和金鑰儲存標誌初始化該類別的新 X509Certificate2 實例。

X509Certificate2(Byte[], SecureString, X509KeyStorageFlags)
已淘汰.

使用位元組陣列、密碼和金鑰儲存標誌初始化該類別的新 X509Certificate2 實例。

X509Certificate2(String, String)
已淘汰.

使用憑證檔案名稱及用於存取憑證的密碼初始化該 X509Certificate2 類別的新實例。

X509Certificate2(String, SecureString)
已淘汰.

使用憑證檔案名稱和密碼初始化該 X509Certificate2 類別的新實例。

X509Certificate2(String, SecureString, X509KeyStorageFlags)
已淘汰.

使用憑證檔案名稱、密碼及金鑰儲存標誌初始化該類別的新 X509Certificate2 實例。

X509Certificate2(SerializationInfo, StreamingContext)
已淘汰.

使用指定的序列化與串流上下文資訊初始化該類別的新 X509Certificate2 實例。

X509Certificate2(Byte[], SecureString)
已淘汰.

使用位元組陣列和密碼初始化該類別的新 X509Certificate2 實例。

X509Certificate2(String)
已淘汰.

使用憑證檔案名稱初始化該 X509Certificate2 類別的新實例。

X509Certificate2(X509Certificate)

使用X509Certificate2物件初始化該類別的新實例X509Certificate。

X509Certificate2(ReadOnlySpan<Byte>)
已淘汰.

從憑證資料初始化該類別的新實例 X509Certificate2 。

X509Certificate2(IntPtr)

使用非管理的句柄初始化該 X509Certificate2 類別的新實例。

X509Certificate2(Byte[])
已淘汰.

利用位元組陣列中的資訊初始化該類別的新 X509Certificate2 實例。

X509Certificate2(Byte[], String)
已淘汰.

使用位元組陣列和密碼初始化該類別的新 X509Certificate2 實例。

X509Certificate2(String, String, X509KeyStorageFlags)
已淘汰.

使用憑證檔案名稱、用於存取憑證的密碼及金鑰儲存標誌初始化該類別的新 X509Certificate2 實例。

X509Certificate2()

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
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:
 X509Certificate2();
[System.Obsolete("X509Certificate and X509Certificate2 are immutable. Use X509CertificateLoader to create a new certificate.", DiagnosticId="SYSLIB0026", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
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.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[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();
Public Sub New ()
屬性

範例

以下程式碼範例開啟目前使用者憑證庫,只選擇啟用的憑證,然後允許使用者選擇一個或多個憑證。 範例接著將憑證資訊寫入主控台。

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, ReadOnlySpan<Char>, X509KeyStorageFlags)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs

警告

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

使用憑證檔案名稱、密碼及金鑰儲存標誌初始化該類別的新 X509Certificate2 實例。

[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}")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(string fileName, ReadOnlySpan<char> password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags = System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.DefaultKeySet);
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.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}")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * ReadOnlySpan<char> * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2
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
Public 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

這是一組位元組合的列舉值,控制憑證的匯入地點與方式。

屬性

例外狀況

憑證出錯了。 例如:

  • 該憑證檔案不存在。

  • 憑證無效。

  • 證書的密碼不正確。

備註

Important

千萬不要在原始碼裡硬寫密碼。 硬編碼密碼可透過 Ildasm.exe(IL 反組譯器)、十六進位編輯器,或直接在文字編輯器如 Notepad.exe中開啟組合語言擷取。

如果你透過指定一個 PKCS7 簽署的檔案儲存X509Certificate2庫來建立fileName憑證,則X509Certificate2是為簽署儲存庫的憑證建立,而非儲存庫內的任何憑證。

適用於

X509Certificate2(ReadOnlySpan<Byte>, ReadOnlySpan<Char>, X509KeyStorageFlags)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs

警告

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

從憑證資料、密碼及金鑰儲存旗標初始化該類別的新實例 X509Certificate2 。

[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}")]
[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);
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.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}")>]
[<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
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
Public 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, X509KeyStorageFlags)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
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);
[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}")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(byte[] rawData, 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);
public X509Certificate2(byte[] rawData, string password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[<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}")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2
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
Public 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)。

Important

千萬不要在原始碼裡硬寫密碼。 硬編碼密碼可透過 Ildasm.exe(IL 反組譯器)、十六進位編輯器,或直接在文字編輯器如 Notepad.exe中開啟組合語言擷取。

如果你透過指定一個 PKCS7 簽署的檔案儲存X509Certificate2庫來建立rawData憑證,則X509Certificate2是為簽署儲存庫的憑證建立,而非儲存庫內的任何憑證。

適用於

X509Certificate2(Byte[], SecureString, X509KeyStorageFlags)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
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)]
[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}")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
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);
[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)]
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)>]
[<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}")>]
[<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)>]
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
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2
Public 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)。

Important

千萬不要在原始碼裡硬寫密碼。 硬編碼密碼可透過 Ildasm.exe(IL 反組譯器)、十六進位編輯器,或直接在文字編輯器如 Notepad.exe中開啟組合語言擷取。

如果你透過指定一個 PKCS7 簽署的檔案儲存X509Certificate庫來建立rawData憑證,則X509Certificate是為簽署儲存庫的憑證建立,而非儲存庫內的任何憑證。

適用於

X509Certificate2(String, String)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
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.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}")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(string fileName, string? password);
public X509Certificate2(string fileName, string? password);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(string fileName, string? password);
public X509Certificate2(string fileName, string password);
[<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}")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * string -> System.Security.Cryptography.X509Certificates.X509Certificate2
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
Public Sub New (fileName As String, password As String)

參數

fileName
String

一個憑證檔案的名稱。

password
String

存取 X.509 憑證資料所需的密碼。

屬性

例外狀況

憑證出錯了。 例如:

  • 該憑證檔案不存在。

  • 憑證無效。

  • 證書的密碼不正確。

備註

此建構器使用憑證檔案名稱及存取憑證所需的密碼,建立一個新的 X509Certificate2 物件。 它與包含憑證私鑰的 PKCS12(PFX)檔案一起使用。 用正確密碼呼叫此構造子,解密私鑰並將其儲存到金鑰容器中。

Important

千萬不要在原始碼裡硬寫密碼。 硬編碼密碼可透過 Ildasm.exe(IL 反組譯器)、十六進位編輯器,或直接在文字編輯器如 Notepad.exe中開啟組合語言擷取。

如果你透過指定一個 PKCS7 簽署的檔案儲存X509Certificate2庫來建立fileName憑證,則X509Certificate2是為簽署儲存庫的憑證建立,而非儲存庫內的任何憑證。

適用於

X509Certificate2(String, SecureString)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
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)]
[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}")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(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)]
public X509Certificate2(string fileName, System.Security.SecureString password);
public X509Certificate2(string fileName, System.Security.SecureString password);
[<System.CLSCompliant(false)>]
[<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}")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate2
[<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
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate2
Public Sub New (fileName As String, password As SecureString)

參數

fileName
String

一個憑證檔案的名稱。

password
SecureString

存取 X.509 憑證資料所需的密碼。

屬性

例外狀況

憑證出錯了。 例如:

  • 該憑證檔案不存在。

  • 憑證無效。

  • 證書的密碼不正確。

備註

此建構器用於包含憑證私鑰的 PKCS12(PFX)檔案。 用正確密碼呼叫此構造子,解密私鑰並將其儲存到金鑰容器中。

Important

千萬不要在原始碼裡硬寫密碼。 硬編碼密碼可透過 Ildasm.exe(IL 反組譯器)、十六進位編輯器,或直接在文字編輯器如 Notepad.exe中開啟組合語言擷取。

如果你透過指定一個 PKCS7 簽署的檔案儲存X509Certificate庫來建立fileName憑證,則X509Certificate是為簽署儲存庫的憑證建立,而非儲存庫內的任何憑證。

適用於

X509Certificate2(String, SecureString, X509KeyStorageFlags)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
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)]
[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}")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
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);
[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)]
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)>]
[<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}")>]
[<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)>]
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
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2
Public Sub New (fileName As String, password As SecureString, keyStorageFlags As X509KeyStorageFlags)

參數

fileName
String

一個憑證檔案的名稱。

password
SecureString

存取 X.509 憑證資料所需的密碼。

keyStorageFlags
X509KeyStorageFlags

這是一組位元組合的列舉值,控制憑證的匯入地點與方式。

屬性

例外狀況

憑證出錯了。 例如:

  • 該憑證檔案不存在。

  • 憑證無效。

  • 證書的密碼不正確。

備註

如果你透過指定一個 PKCS7 簽署的檔案儲存X509Certificate庫來建立fileName憑證,則X509Certificate是為簽署儲存庫的憑證建立,而非儲存庫內的任何憑證。

適用於

X509Certificate2(SerializationInfo, StreamingContext)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
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);
[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);
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}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Cryptography.X509Certificates.X509Certificate2
new System.Security.Cryptography.X509Certificates.X509Certificate2 : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Cryptography.X509Certificates.X509Certificate2
Protected Sub New (info As SerializationInfo, context As StreamingContext)

參數

info
SerializationInfo

去序列化 X509Certificate2新 . 所需的序列化資訊。

context
StreamingContext

關於被反序列化串流來源的上下文資訊。

屬性

例外狀況

僅限 .NET Core 和 .NET 5+:適用於所有情況。

適用於

X509Certificate2(Byte[], SecureString)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
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)]
[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}")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(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)]
public X509Certificate2(byte[] rawData, System.Security.SecureString password);
public X509Certificate2(byte[] rawData, System.Security.SecureString password);
[<System.CLSCompliant(false)>]
[<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}")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate2
[<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
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate2
Public Sub New (rawData As Byte(), password As SecureString)

參數

rawData
Byte[]

一個包含 X.509 憑證資料的位元組陣列。

password
SecureString

存取 X.509 憑證資料所需的密碼。

屬性

例外狀況

憑證出錯了。 例如:

  • 該憑證檔案不存在。

  • 憑證無效。

  • 證書的密碼不正確。

備註

此建構器用於包含憑證私鑰的 PKCS12(PFX)檔案。 用正確密碼呼叫此構造子,解密私鑰並將其儲存到金鑰容器中。

Important

千萬不要在原始碼裡硬寫密碼。 硬編碼密碼可透過 Ildasm.exe(IL 反組譯器)、十六進位編輯器,或直接在文字編輯器如 Notepad.exe中開啟組合語言擷取。

如果你透過指定一個 PKCS7 簽署的檔案儲存X509Certificate庫來建立rawData憑證,則X509Certificate是為簽署儲存庫的憑證建立,而非儲存庫內的任何憑證。

適用於

X509Certificate2(String)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
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.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}")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(string fileName);
public X509Certificate2(string fileName);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(string fileName);
[<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}")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string -> System.Security.Cryptography.X509Certificates.X509Certificate2
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
Public Sub New (fileName As String)

參數

fileName
String

一個憑證檔案的名稱。

屬性

例外狀況

憑證出錯了。 例如:

  • 該憑證檔案不存在。

  • 憑證無效。

  • 證書的密碼不正確。

備註

此建構器使用憑證檔案名稱建立一個新 X509Certificate2 物件。 它支援二進位(DER)編碼或 PEM 編碼。

如果你透過指定一個 PKCS7 簽署的檔案儲存X509Certificate2庫來建立fileName憑證,則X509Certificate2是為簽署儲存庫的憑證建立,而非儲存庫內的任何憑證。

適用於

X509Certificate2(X509Certificate)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs

使用X509Certificate2物件初始化該類別的新實例X509Certificate。

public:
 X509Certificate2(System::Security::Cryptography::X509Certificates::X509Certificate ^ certificate);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(System.Security.Cryptography.X509Certificates.X509Certificate certificate);
public X509Certificate2(System.Security.Cryptography.X509Certificates.X509Certificate certificate);
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : System.Security.Cryptography.X509Certificates.X509Certificate -> System.Security.Cryptography.X509Certificates.X509Certificate2
new System.Security.Cryptography.X509Certificates.X509Certificate2 : System.Security.Cryptography.X509Certificates.X509Certificate -> System.Security.Cryptography.X509Certificates.X509Certificate2
Public Sub New (certificate As X509Certificate)

參數

certificate
X509Certificate

X509Certificate 物件。

屬性

例外狀況

憑證出錯了。 例如:

  • 該憑證檔案不存在。

  • 憑證無效。

  • 證書的密碼不正確。

備註

此方法會使用物件X509Certificate2建立該類別的新實例X509Certificate。

適用於

X509Certificate2(ReadOnlySpan<Byte>)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
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);
[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}")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(ReadOnlySpan<byte> rawData);
public X509Certificate2(ReadOnlySpan<byte> rawData);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(ReadOnlySpan<byte> rawData);
[<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}")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : ReadOnlySpan<byte> -> System.Security.Cryptography.X509Certificates.X509Certificate2
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
Public Sub New (rawData As ReadOnlySpan(Of Byte))

參數

rawData
ReadOnlySpan<Byte>

要處理的證書資料。

屬性

例外狀況

憑證出錯了。

適用於

X509Certificate2(IntPtr)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs

使用非管理的句柄初始化該 X509Certificate2 類別的新實例。

public:
 X509Certificate2(IntPtr handle);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(IntPtr handle);
public X509Certificate2(IntPtr handle);
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : nativeint -> System.Security.Cryptography.X509Certificates.X509Certificate2
new System.Security.Cryptography.X509Certificates.X509Certificate2 : nativeint -> System.Security.Cryptography.X509Certificates.X509Certificate2
Public Sub New (handle As IntPtr)

參數

handle
IntPtr

nativeint

一個指向非管理程式碼中憑證上下文的指標。 C 結構稱為 PCCERT_CONTEXT。

屬性

例外狀況

憑證出錯了。 例如:

  • 該憑證檔案不存在。

  • 憑證無效。

  • 證書的密碼不正確。

備註

此建構器會利用 Microsoft 密碼 API 憑證上下文的句柄建立一個新X509Certificate2物件。 PCCERT_CONTEXT 請注意,此建構子的直接呼叫者需要非管理程式碼權限。

Important

建構子會建立憑證上下文的副本。 不要假設你交給建構子的上下文結構是有效的;可能已經被釋放了。 你可以從該PCCERT_CONTEXT屬性取得目前Handle結構的副本,但該結構只在物件的X509Certificate2存續期間有效。

適用於

X509Certificate2(Byte[])

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
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.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}")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(byte[] rawData);
public X509Certificate2(byte[] rawData);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(byte[] rawData);
[<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}")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] -> System.Security.Cryptography.X509Certificates.X509Certificate2
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
Public Sub New (rawData As Byte())

參數

rawData
Byte[]

一個包含 X.509 憑證資料的位元組陣列。

屬性

例外狀況

憑證出錯了。 例如:

  • 該憑證檔案不存在。

  • 憑證無效。

  • 證書的密碼不正確。

備註

此建構子利用位元組陣列中的憑證資訊建立新 X509Certificate2 物件。 位元組陣列可以是二進位(DER)編碼,也可以是 PEM 編碼的 X.509 資料。 位元組陣列也可以是 PKCS7(Authenticode)簽名檔案;簽署者憑證用於建立物件。

如果你透過指定一個 PKCS7 簽署的檔案儲存X509Certificate2庫來建立rawData憑證,則X509Certificate2是為簽署儲存庫的憑證建立,而非儲存庫內的任何憑證。

適用於

X509Certificate2(Byte[], String)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
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.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}")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(byte[] rawData, string? password);
public X509Certificate2(byte[] rawData, string? password);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(byte[] rawData, string? password);
public X509Certificate2(byte[] rawData, string password);
[<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}")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : byte[] * string -> System.Security.Cryptography.X509Certificates.X509Certificate2
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
Public Sub New (rawData As Byte(), password As String)

參數

rawData
Byte[]

一個包含 X.509 憑證資料的位元組陣列。

password
String

存取 X.509 憑證資料所需的密碼。

屬性

例外狀況

憑證出錯了。 例如:

  • 該憑證檔案不存在。

  • 憑證無效。

  • 證書的密碼不正確。

備註

此建構器利用位元組陣列和密碼建立一個新 X509Certificate2 物件,該密碼是存取憑證資料所需的。 它與包含憑證私鑰的 PKCS12(PFX)檔案一起使用。 用正確密碼呼叫此構造子,解密私鑰並將其儲存到金鑰容器中。

Important

千萬不要在原始碼裡硬寫密碼。 硬編碼密碼可透過 Ildasm.exe(IL 反組譯器)、十六進位編輯器,或直接在文字編輯器如 Notepad.exe中開啟組合語言擷取。

如果你透過指定一個 PKCS7 簽署的檔案儲存X509Certificate2庫來建立rawData憑證,則X509Certificate2是為簽署儲存庫的憑證建立,而非儲存庫內的任何憑證。

適用於

X509Certificate2(String, String, X509KeyStorageFlags)

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
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);
[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}")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate2(string fileName, 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);
public X509Certificate2(string fileName, string password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[<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}")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate2 : string * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate2
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
Public Sub New (fileName As String, password As String, keyStorageFlags As X509KeyStorageFlags)

參數

fileName
String

一個憑證檔案的名稱。

password
String

存取 X.509 憑證資料所需的密碼。

keyStorageFlags
X509KeyStorageFlags

這是一組位元組合的列舉值,控制憑證的匯入地點與方式。

屬性

例外狀況

憑證出錯了。 例如:

  • 該憑證檔案不存在。

  • 憑證無效。

  • 證書的密碼不正確。

備註

此建構器使用憑證檔案名稱、存取憑證所需的密碼及金鑰儲存標誌來建立一個新 X509Certificate2 物件。

Important

千萬不要在原始碼裡硬寫密碼。 硬編碼密碼可透過 Ildasm.exe(IL 反組譯器)、十六進位編輯器,或直接在文字編輯器如 Notepad.exe中開啟組合語言擷取。

如果你透過指定一個 PKCS7 簽署的檔案儲存X509Certificate2庫來建立fileName憑證,則X509Certificate2是為簽署儲存庫的憑證建立,而非儲存庫內的任何憑證。

適用於