共用方式為


X509Certificate2 建構函式

定義

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

多載

X509Certificate2()
已淘汰.
已淘汰.

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

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

使用憑證檔名、用於存取憑證的密碼和金鑰儲存旗標,初始化 X509Certificate2 類別的新執行個體。

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

使用憑證檔名、密碼和金鑰儲存旗標,初始化 X509Certificate2 類別的新執行個體。

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

使用憑證檔名、密碼和金鑰儲存旗標,初始化 X509Certificate2 類別的新執行個體。

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

使用位元組陣列、密碼和金鑰儲存旗標,初始化 X509Certificate2 類別的新執行個體。

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

使用位元組陣列、密碼和金鑰儲存旗標,初始化 X509Certificate2 類別的新執行個體。

X509Certificate2(String, String)
已淘汰.

使用憑證檔名和用於存取憑證的密碼,初始化 X509Certificate2 類別的新執行個體。

X509Certificate2(String, SecureString)
已淘汰.

使用憑證檔名和密碼,初始化 X509Certificate2 類別的新執行個體。

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

從憑證資料、密碼與金鑰儲存旗標,將 X509Certificate2 類別的新執行個體初始化。

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

使用位元組陣列和密碼,初始化 X509Certificate2 類別的新執行個體。

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

使用位元組陣列和密碼,初始化 X509Certificate2 類別的新執行個體。

X509Certificate2(String)
已淘汰.

使用憑證檔名,初始化 X509Certificate2 類別的新執行個體。

X509Certificate2(X509Certificate)

使用 X509Certificate2 物件,初始化 X509Certificate 類別的新執行個體。

X509Certificate2(SerializationInfo, StreamingContext)
已淘汰.

使用指定的序列化和資料流內容資訊,初始化 X509Certificate2 類別的新執行個體。

X509Certificate2(ReadOnlySpan<Byte>)
已淘汰.

從憑證資料中,初始化 X509Certificate2 類別的新執行個體。

X509Certificate2(IntPtr)

使用 Unmanaged 控制代碼,初始化 X509Certificate2 類別的新執行個體。

X509Certificate2(Byte[])
已淘汰.

使用位元組陣列中的資訊,初始化 X509Certificate2 類別的新執行個體。

X509Certificate2()

來源:
X509Certificate2.cs
來源:
X509Certificate2.cs
來源:
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)

來源:
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);
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.X509Certificate2
Public 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,從元件擷取。

如果您藉由為 指定 PKCS7 簽署的檔案存放區來建立X509Certificate2憑證,X509Certificate2則會針對簽署存放區的fileName憑證建立 ,而不是針對存放區中的任何憑證建立 。

適用於

X509Certificate2(String, SecureString, X509KeyStorageFlags)

來源:
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)]
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.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憑證,X509Certificate則會針對簽署存放區的fileName憑證建立 ,而不是針對存放區中的任何憑證建立 。

適用於

X509Certificate2(String, ReadOnlySpan<Char>, X509KeyStorageFlags)

來源:
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 (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.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

列舉值的位元組合,會控制匯入憑證的位置和方式。

屬性

例外狀況

此憑證發生錯誤。 例如:

  • 憑證檔案不存在。

  • 憑證無效。

  • 憑證的密碼不正確。

備註

重要

請勿在原始程式碼中硬式編碼密碼。 硬式編碼的密碼可以使用 Ildasm.exe (IL 反組譯程式) 、十六進位編輯器,或在文本編輯器中開啟元件,例如 Notepad.exe,從元件擷取。

如果您藉由為 指定 PKCS7 簽署的檔案存放區來建立X509Certificate2憑證,X509Certificate2則會針對簽署存放區的fileName憑證建立 ,而不是針對存放區中的任何憑證建立 。

適用於

X509Certificate2(Byte[], String, X509KeyStorageFlags)

來源:
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);
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.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) 。

重要

請勿在原始程式碼中硬式編碼密碼。 硬式編碼的密碼可以使用 Ildasm.exe (IL 反組譯程式) 、十六進位編輯器,或在文本編輯器中開啟元件,例如 Notepad.exe,從元件擷取。

如果您藉由為 指定 PKCS7 簽署的檔案存放區來建立X509Certificate2憑證,X509Certificate2則會針對簽署存放區的rawData憑證建立 ,而不是針對存放區中的任何憑證建立 。

適用於

X509Certificate2(Byte[], SecureString, X509KeyStorageFlags)

來源:
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)]
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.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) 。

重要

絕對不要在原始程式碼內硬式編碼密碼。 硬式編碼的密碼可以使用 Ildasm.exe (IL 反組譯程式) 、十六進位編輯器,或直接在文本編輯器中開啟元件,例如 Notepad.exe 來擷取元件。

如果您藉由指定的 rawDataPKCS7 簽署檔案存放區來建立X509Certificate憑證,則會X509Certificate針對簽署存放區的憑證建立 ,而不是針對存放區內的任何憑證建立。

適用於

X509Certificate2(String, String)

來源:
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);
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.X509Certificate2
Public Sub New (fileName As String, password As String)

參數

fileName
String

憑證檔的名稱。

password
String

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

屬性

例外狀況

此憑證發生錯誤。 例如:

  • 憑證檔案不存在。

  • 憑證無效。

  • 憑證的密碼不正確。

備註

這個建構函式會使用憑證檔名和存取憑證所需的密碼,建立新的 X509Certificate2 物件。 它與包含憑證私鑰的 PKCS12 (PFX) 檔案搭配使用。 使用正確的密碼呼叫此建構函式會解密私鑰,並將它儲存至密鑰容器。

重要

絕對不要在原始程式碼內硬式編碼密碼。 硬式編碼的密碼可以使用 Ildasm.exe (IL 反組譯程式) 、十六進位編輯器,或直接在文本編輯器中開啟元件,例如 Notepad.exe 來擷取元件。

如果您藉由指定的 fileNamePKCS7 簽署檔案存放區來建立X509Certificate2憑證,則會X509Certificate2針對簽署存放區的憑證建立 ,而不是針對存放區內的任何憑證建立。

適用於

X509Certificate2(String, SecureString)

來源:
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)]
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.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) 檔案搭配使用。 使用正確的密碼呼叫此建構函式會解密私鑰,並將它儲存至密鑰容器。

重要

絕對不要在原始程式碼內硬式編碼密碼。 硬式編碼的密碼可以使用 Ildasm.exe (IL 反組譯程式) 、十六進位編輯器,或直接在文本編輯器中開啟元件,例如 Notepad.exe 來擷取元件。

如果您藉由指定的 fileNamePKCS7 簽署檔案存放區來建立X509Certificate憑證,則會X509Certificate針對簽署存放區的憑證建立 ,而不是針對存放區內的任何憑證建立。

適用於

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

來源:
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<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.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)

來源:
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);
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.X509Certificate2
Public Sub New (rawData As Byte(), password As String)

參數

rawData
Byte[]

位元組陣列,包含來自 X.509 憑證的資料。

password
String

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

屬性

例外狀況

此憑證發生錯誤。 例如:

  • 憑證檔案不存在。

  • 憑證無效。

  • 憑證的密碼不正確。

備註

這個建構函式會使用位元組數位和存取憑證數據所需的密碼來建立新的 X509Certificate2 物件。 它與包含憑證私鑰的 PKCS12 (PFX) 檔案搭配使用。 使用正確的密碼呼叫此建構函式會解密私鑰,並將它儲存至密鑰容器。

重要

絕對不要在原始程式碼內硬式編碼密碼。 硬式編碼的密碼可以使用 Ildasm.exe (IL 反組譯程式) 、十六進位編輯器,或直接在文本編輯器中開啟元件,例如 Notepad.exe 來擷取元件。

如果您藉由指定的 rawDataPKCS7 簽署檔案存放區來建立X509Certificate2憑證,則會X509Certificate2針對簽署存放區的憑證建立 ,而不是針對存放區內的任何憑證建立。

適用於

X509Certificate2(Byte[], SecureString)

來源:
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)]
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.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) 檔案搭配使用。 使用正確的密碼呼叫此建構函式會解密私鑰,並將它儲存至密鑰容器。

重要

絕對不要在原始程式碼內硬式編碼密碼。 硬式編碼的密碼可以使用 Ildasm.exe (IL 反組譯程式) 、十六進位編輯器,或直接在文本編輯器中開啟元件,例如 Notepad.exe 來擷取元件。

如果您藉由指定的 rawDataPKCS7 簽署檔案存放區來建立X509Certificate憑證,則會X509Certificate針對簽署存放區的憑證建立 ,而不是針對存放區內的任何憑證建立。

適用於

X509Certificate2(String)

來源:
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);
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.X509Certificate2
Public Sub New (fileName As String)

參數

fileName
String

憑證檔的名稱。

屬性

例外狀況

此憑證發生錯誤。 例如:

  • 憑證檔案不存在。

  • 憑證無效。

  • 憑證的密碼不正確。

備註

這個建構函式會使用憑證檔名建立新的 X509Certificate2 物件。 它支援二進位 (DER) 編碼或Base64編碼。

如果您藉由指定的 fileNamePKCS7 簽署檔案存放區來建立X509Certificate2憑證,則會X509Certificate2針對簽署存放區的憑證建立 ,而不是針對存放區內的任何憑證建立。

適用於

X509Certificate2(X509Certificate)

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

使用 X509Certificate2 物件,初始化 X509Certificate 類別的新執行個體。

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.X509Certificate2
Public Sub New (certificate As X509Certificate)

參數

certificate
X509Certificate

X509Certificate 物件。

屬性

例外狀況

此憑證發生錯誤。 例如:

  • 憑證檔案不存在。

  • 憑證無效。

  • 憑證的密碼不正確。

備註

這個方法會使用 X509Certificate 物件建立 類別的新實例X509Certificate2

適用於

X509Certificate2(SerializationInfo, StreamingContext)

來源:
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);
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.X509Certificate2
Protected Sub New (info As SerializationInfo, context As StreamingContext)

參數

info
SerializationInfo

還原序列化新的 X509Certificate2 所需的序列化資訊。

context
StreamingContext

關於要還原序列化之資料流來源的內容資訊。

屬性

例外狀況

僅限 .NET Core 與 .NET 5+:在所有情況下。

適用於

X509Certificate2(ReadOnlySpan<Byte>)

來源:
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);
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.X509Certificate2
Public Sub New (rawData As ReadOnlySpan(Of Byte))

參數

rawData
ReadOnlySpan<Byte>

要處理的憑證數據。

屬性

例外狀況

此憑證發生錯誤。

適用於

X509Certificate2(IntPtr)

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

使用 Unmanaged 控制代碼,初始化 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.X509Certificate2
Public Sub New (handle As IntPtr)

參數

handle
IntPtr

nativeint

指向 Unmanaged 程式碼中憑證內容的指標。 C 結構稱為 PCCERT_CONTEXT

屬性

例外狀況

此憑證發生錯誤。 例如:

  • 憑證檔案不存在。

  • 憑證無效。

  • 憑證的密碼不正確。

備註

此建構函式會使用 Microsoft 密碼編譯 API 憑證內容的PCCERT_CONTEXT句柄來建立新的 X509Certificate2 物件。 請注意,此建構函式的立即呼叫端需要 Unmanaged 程式代碼許可權。

重要

建構函式會建立憑證內容的複本。 請勿假設您傳遞至建構函式的內容結構有效;它可能已發行。 您可以從 屬性取得目前 PCCERT_CONTEXT 結構的 Handle 複本,但只有在物件的存 X509Certificate2 留期期間才有效。

適用於

X509Certificate2(Byte[])

來源:
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);
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.X509Certificate2
Public Sub New (rawData As Byte())

參數

rawData
Byte[]

位元組陣列,包含來自 X.509 憑證的資料。

屬性

例外狀況

此憑證發生錯誤。 例如:

  • 憑證檔案不存在。

  • 憑證無效。

  • 憑證的密碼不正確。

備註

此建構函式會使用位元組數位列中的憑證資訊建立新的 X509Certificate2 物件。 位元組陣列可以是編碼的二進位 (DER) 或 Base64 編碼的 X.509 資料。 位元組陣組也可以是 PKCS7 (Authenticode) 簽署的檔案;簽署者憑證是用來建立物件。

如果您藉由為 指定 PKCS7 簽署的檔案存放區來建立X509Certificate2憑證,X509Certificate2則會針對簽署存放區的rawData憑證建立 ,而不是針對存放區中的任何憑證建立 。

適用於