X509Certificate 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 X509Certificate 類別的新執行個體。
多載
X509Certificate()
警告
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.
初始化 X509Certificate 類別的新執行個體。
public:
X509Certificate();
public X509Certificate ();
[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 X509Certificate ();
[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 X509Certificate ();
[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 X509Certificate ();
Public Sub New ()
- 屬性
備註
ASN.1 DER 是唯一此類別支援的憑證格式。
適用於
X509Certificate(Byte[])
警告
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
初始化 X509Certificate 類別的新執行個體 (這個類別是在表示 X.509v3 憑證的位元組序列中定義的)。
public:
X509Certificate(cli::array <System::Byte> ^ data);
public X509Certificate (byte[] data);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate (byte[] data);
[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 X509Certificate (byte[] data);
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<System.Obsolete("Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.", DiagnosticId="SYSLIB0057", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (data As Byte())
參數
- data
- Byte[]
位元組陣列,包含來自 X.509 憑證的資料。
- 屬性
例外狀況
範例
下列範例會將 X.509 憑證檔案 X509Certificate 載入物件、將憑證匯出為位元組陣列,然後將位元組數位數位組匯入另一個 X509Certificate 物件。
using namespace System;
using namespace System::Security::Cryptography::X509Certificates;
int main()
{
// The path to the certificate.
String^ Certificate = L"test.pfx";
// Load the certificate into an X509Certificate object.
X509Certificate^ cert = gcnew X509Certificate( Certificate );
array<Byte>^certData = cert->Export( X509ContentType::Cert );
X509Certificate^ newCert = gcnew X509Certificate( certData );
// Get the value.
String^ resultsTrue = newCert->ToString( true );
// Display the value to the console.
Console::WriteLine( resultsTrue );
// Get the value.
String^ resultsFalse = newCert->ToString( false );
// Display the value to the console.
Console::WriteLine( resultsFalse );
}
using System;
using System.Security.Cryptography.X509Certificates;
public class X509
{
public static void Main()
{
// The path to the certificate.
string Certificate = "test.pfx";
// Load the certificate into an X509Certificate object.
X509Certificate cert = new X509Certificate(Certificate);
byte[] certData = cert.Export(X509ContentType.Cert);
X509Certificate newCert = new X509Certificate(certData);
// Get the value.
string resultsTrue = newCert.ToString(true);
// Display the value to the console.
Console.WriteLine(resultsTrue);
// Get the value.
string resultsFalse = newCert.ToString(false);
// Display the value to the console.
Console.WriteLine(resultsFalse);
}
}
Imports System.Security.Cryptography.X509Certificates
Module X509
Sub Main()
' The path to the certificate.
Dim Certificate As String = "test.pfx"
' Load the certificate into an X509Certificate object.
Dim cert As New X509Certificate(Certificate)
Dim certData As Byte() = cert.Export(X509ContentType.Cert)
Dim newCert As New X509Certificate(certData)
' Get the value.
Dim resultsTrue As String = newCert.ToString(True)
' Display the value to the console.
Console.WriteLine(resultsTrue)
' Get the value.
Dim resultsFalse As String = newCert.ToString(False)
' Display the value to the console.
Console.WriteLine(resultsFalse)
End Sub
End Module
備註
ASN.1 DER 是唯一此類別支援的憑證格式。
如果您藉由指定的 data
PKCS7 簽署檔案存放區來建立X509Certificate憑證,則會X509Certificate針對簽署存放區的憑證建立 ,而不是針對存放區內的任何憑證建立。
適用於
X509Certificate(IntPtr)
使用 Unmanaged PCCERT_CONTEXT
結構的控制代碼,初始化 X509Certificate 類別的新執行個體。
public:
X509Certificate(IntPtr handle);
public X509Certificate (IntPtr handle);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate (IntPtr handle);
[System.Security.SecurityCritical]
public X509Certificate (IntPtr handle);
new System.Security.Cryptography.X509Certificates.X509Certificate : nativeint -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : nativeint -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Security.SecurityCritical>]
new System.Security.Cryptography.X509Certificates.X509Certificate : nativeint -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (handle As IntPtr)
參數
- handle
-
IntPtr
nativeint
Unmanaged PCCERT_CONTEXT
結構的控制代碼。
- 屬性
例外狀況
此控制代碼參數不表示有效的 PCCERT_CONTEXT
結構。
備註
此建構函式會使用 Microsoft 密碼編譯 API 憑證內容的PCCERT_CONTEXT
句柄建立新的 X509Certificate 物件。
重要
此建構函式會建立憑證內容的複本。 請勿假設您傳遞至建構函式的內容結構有效;它可能已釋出。 您可以從 屬性取得目前 PCCERT_CONTEXT
結構的 Handle 複本,但只有在物件的存留期 X509Certificate 期間才有效。
適用於
X509Certificate(X509Certificate)
使用另一個 X509Certificate 類別,初始化 X509Certificate 類別的新執行個體。
public:
X509Certificate(System::Security::Cryptography::X509Certificates::X509Certificate ^ cert);
public X509Certificate (System.Security.Cryptography.X509Certificates.X509Certificate cert);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate (System.Security.Cryptography.X509Certificates.X509Certificate cert);
new System.Security.Cryptography.X509Certificates.X509Certificate : System.Security.Cryptography.X509Certificates.X509Certificate -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : System.Security.Cryptography.X509Certificates.X509Certificate -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (cert As X509Certificate)
參數
- cert
- X509Certificate
初始化這個類別的 X509Certificate 類別。
- 屬性
例外狀況
cert
參數的值為 null
。
備註
ASN.1 DER 是唯一此類別支援的憑證格式。
適用於
X509Certificate(String)
警告
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
使用 PKCS7 已簽署檔案的名稱,初始化 X509Certificate 類別的新執行個體。
public:
X509Certificate(System::String ^ fileName);
public X509Certificate (string fileName);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate (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 X509Certificate (string fileName);
new System.Security.Cryptography.X509Certificates.X509Certificate : string -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : string -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<System.Obsolete("Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.", DiagnosticId="SYSLIB0057", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : string -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (fileName As String)
參數
- fileName
- String
PKCS7 已簽署檔案的名稱。
- 屬性
例外狀況
fileName
參數為 null
。
範例
下列範例會從檔案載入 X.509 憑證、呼叫 ToString 方法,並將結果顯示至主控台。
using namespace System;
using namespace System::Security::Cryptography::X509Certificates;
int main()
{
// The path to the certificate.
String^ Certificate = L"Certificate.cer";
// Load the certificate into an X509Certificate object.
X509Certificate^ cert = gcnew X509Certificate( Certificate );
// Get the value.
String^ resultsTrue = cert->ToString( true );
// Display the value to the console.
Console::WriteLine( resultsTrue );
// Get the value.
String^ resultsFalse = cert->ToString( false );
// Display the value to the console.
Console::WriteLine( resultsFalse );
}
using System;
using System.Security.Cryptography.X509Certificates;
public class X509
{
public static void Main()
{
// The path to the certificate.
string Certificate = "Certificate.cer";
// Load the certificate into an X509Certificate object.
X509Certificate cert = new X509Certificate(Certificate);
// Get the value.
string resultsTrue = cert.ToString(true);
// Display the value to the console.
Console.WriteLine(resultsTrue);
// Get the value.
string resultsFalse = cert.ToString(false);
// Display the value to the console.
Console.WriteLine(resultsFalse);
}
}
Imports System.Security.Cryptography.X509Certificates
Module X509
Sub Main()
' The path to the certificate.
Dim Certificate As String = "Certificate.cer"
' Load the certificate into an X509Certificate object.
Dim cert As New X509Certificate(Certificate)
' Get the value.
Dim resultsTrue As String = cert.ToString(True)
' Display the value to the console.
Console.WriteLine(resultsTrue)
' Get the value.
Dim resultsFalse As String = cert.ToString(False)
' Display the value to the console.
Console.WriteLine(resultsFalse)
End Sub
End Module
備註
ASN.1 DER 是唯一此類別支援的憑證格式。
如果您藉由指定的 fileName
PKCS7 簽署檔案存放區來建立X509Certificate憑證,則會X509Certificate針對簽署存放區的憑證建立 ,而不是針對存放區內的任何憑證建立。
適用於
X509Certificate(Byte[], SecureString)
警告
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
重要
此 API 不符合 CLS 規範。
使用位元組陣列和密碼,初始化 X509Certificate 類別的新執行個體。
public:
X509Certificate(cli::array <System::Byte> ^ rawData, System::Security::SecureString ^ password);
[System.CLSCompliant(false)]
public X509Certificate (byte[] rawData, System.Security.SecureString? password);
[System.CLSCompliant(false)]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate (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 X509Certificate (byte[] rawData, System.Security.SecureString? password);
[System.CLSCompliant(false)]
public X509Certificate (byte[] rawData, System.Security.SecureString password);
public X509Certificate (byte[] rawData, System.Security.SecureString password);
[<System.CLSCompliant(false)>]
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.CLSCompliant(false)>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate
[<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.X509Certificate : byte[] * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (rawData As Byte(), password As SecureString)
參數
- rawData
- Byte[]
位元組陣列,包含來自 X.509 憑證的資料。
- password
- SecureString
存取 X.509 憑證資料所需的密碼。
- 屬性
例外狀況
備註
ASN.1 DER 是唯一此類別支援的憑證格式。
重要
絕對不要在原始程式碼內硬式編碼密碼。 使用 Ildasm.exe (IL 反組譯程式) 、十六進位編輯器,或在文本編輯器中開啟元件,例如 Notepad.exe,即可從元件擷取硬式編碼密碼。
如果您藉由指定的 rawData
PKCS7 簽署檔案存放區來建立X509Certificate憑證,則會X509Certificate針對簽署存放區的憑證建立 ,而不是針對存放區內的任何憑證建立。
適用於
X509Certificate(Byte[], String)
警告
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
使用位元組陣列和密碼,初始化 X509Certificate 類別的新執行個體。
public:
X509Certificate(cli::array <System::Byte> ^ rawData, System::String ^ password);
public X509Certificate (byte[] rawData, string? password);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate (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 X509Certificate (byte[] rawData, string? password);
public X509Certificate (byte[] rawData, string password);
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] * string -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] * string -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<System.Obsolete("Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.", DiagnosticId="SYSLIB0057", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] * string -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (rawData As Byte(), password As String)
參數
- rawData
- Byte[]
位元組陣列,包含來自 X.509 憑證的資料。
- password
- String
存取 X.509 憑證資料所需的密碼。
- 屬性
例外狀況
備註
ASN.1 DER 是唯一此類別支援的憑證格式。
重要
絕對不要在原始程式碼內硬式編碼密碼。 使用 Ildasm.exe (IL 反組譯程式) 、十六進位編輯器,或在文本編輯器中開啟元件,例如 Notepad.exe,即可從元件擷取硬式編碼密碼。
如果您藉由指定的 rawData
PKCS7 簽署檔案存放區來建立X509Certificate憑證,則會X509Certificate針對簽署存放區的憑證建立 ,而不是針對存放區內的任何憑證建立。
適用於
X509Certificate(SerializationInfo, StreamingContext)
警告
This API supports obsolete formatter-based serialization. It should not be called or extended by application code.
使用 X509Certificate 物件和 SerializationInfo 結構,初始化 StreamingContext 類別的新執行個體。
public:
X509Certificate(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
public X509Certificate (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}")]
public X509Certificate (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Security.Cryptography.X509Certificates.X509Certificate : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Cryptography.X509Certificates.X509Certificate
[<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.X509Certificate : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (info As SerializationInfo, context As StreamingContext)
參數
- info
- SerializationInfo
SerializationInfo 物件,描述序列化 (Serialization) 資訊。
- context
- StreamingContext
StreamingContext 結構,描述應如何執行序列化。
- 屬性
例外狀況
適用於
X509Certificate(String, SecureString)
警告
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
重要
此 API 不符合 CLS 規範。
使用憑證檔名和密碼,初始化 X509Certificate 類別的新執行個體。
public:
X509Certificate(System::String ^ fileName, System::Security::SecureString ^ password);
[System.CLSCompliant(false)]
public X509Certificate (string fileName, System.Security.SecureString? password);
[System.CLSCompliant(false)]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate (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 X509Certificate (string fileName, System.Security.SecureString? password);
[System.CLSCompliant(false)]
public X509Certificate (string fileName, System.Security.SecureString password);
public X509Certificate (string fileName, System.Security.SecureString password);
[<System.CLSCompliant(false)>]
new System.Security.Cryptography.X509Certificates.X509Certificate : string * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.CLSCompliant(false)>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : string * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate
[<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.X509Certificate : string * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate
new System.Security.Cryptography.X509Certificates.X509Certificate : string * System.Security.SecureString -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (fileName As String, password As SecureString)
參數
- fileName
- String
憑證檔的名稱。
- password
- SecureString
存取 X.509 憑證資料所需的密碼。
- 屬性
例外狀況
fileName
參數為 null
。
備註
ASN.1 DER 是唯一此類別支援的憑證格式。 使用正確的密碼呼叫此建構函式會解密私鑰,並將它儲存至密鑰容器。
重要
絕對不要在原始程式碼內硬式編碼密碼。 使用 Ildasm.exe (IL 反組譯程式) 、十六進位編輯器,或在文本編輯器中開啟元件,例如 Notepad.exe,即可從元件擷取硬式編碼密碼。
如果您藉由指定的 fileName
PKCS7 簽署檔案存放區來建立X509Certificate憑證,則會X509Certificate針對簽署存放區的憑證建立 ,而不是針對存放區內的任何憑證建立。
適用於
X509Certificate(String, String)
警告
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
使用 PKCS7 已簽署檔案和用於存取憑證的密碼,初始化 X509Certificate 類別的新執行個體。
public:
X509Certificate(System::String ^ fileName, System::String ^ password);
public X509Certificate (string fileName, string? password);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate (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 X509Certificate (string fileName, string? password);
public X509Certificate (string fileName, string password);
new System.Security.Cryptography.X509Certificates.X509Certificate : string * string -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : string * string -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<System.Obsolete("Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.", DiagnosticId="SYSLIB0057", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : string * string -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (fileName As String, password As String)
參數
- fileName
- String
PKCS7 已簽署檔案的名稱。
- password
- String
存取 X.509 憑證資料所需的密碼。
- 屬性
例外狀況
fileName
參數為 null
。
備註
ASN.1 DER 是唯一此類別支援的憑證格式。 使用正確的密碼呼叫此建構函式會解密私鑰,並將它儲存至密鑰容器。
如果您藉由指定的 fileName
PKCS7 簽署檔案存放區來建立X509Certificate憑證,則會X509Certificate針對簽署存放區的憑證建立 ,而不是針對存放區內的任何憑證建立。
適用於
X509Certificate(Byte[], SecureString, X509KeyStorageFlags)
警告
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
重要
此 API 不符合 CLS 規範。
使用位元組陣列、密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。
public:
X509Certificate(cli::array <System::Byte> ^ rawData, System::Security::SecureString ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
public X509Certificate (byte[] rawData, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate (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 X509Certificate (byte[] rawData, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
public X509Certificate (byte[] rawData, System.Security.SecureString password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
public X509Certificate (byte[] rawData, System.Security.SecureString password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[<System.CLSCompliant(false)>]
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.CLSCompliant(false)>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate
[<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.X509Certificate : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (rawData As Byte(), password As SecureString, keyStorageFlags As X509KeyStorageFlags)
參數
- rawData
- Byte[]
位元組陣列,包含來自 X.509 憑證的資料。
- password
- SecureString
存取 X.509 憑證資料所需的密碼。
- keyStorageFlags
- X509KeyStorageFlags
列舉值的位元組合,會控制匯入憑證的位置和方式。
- 屬性
例外狀況
備註
使用正確的密碼呼叫此建構函式會解密私鑰,並將它儲存至 Microsoft 密碼編譯 API 密碼編譯服務提供者 (CSP) 。
ASN.1 DER 是唯一此類別支援的憑證格式。
重要
絕對不要在原始程式碼內硬式編碼密碼。 使用 Ildasm.exe (IL 反組譯程式) 、十六進位編輯器,或在文本編輯器中開啟元件,例如 Notepad.exe,即可從元件擷取硬式編碼密碼。
如果您藉由指定的 rawData
PKCS7 簽署檔案存放區來建立X509Certificate憑證,則會X509Certificate針對簽署存放區的憑證建立 ,而不是針對存放區內的任何憑證建立。
適用於
X509Certificate(Byte[], String, X509KeyStorageFlags)
警告
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
使用位元組陣列、密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。
public:
X509Certificate(cli::array <System::Byte> ^ rawData, System::String ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);
public X509Certificate (byte[] rawData, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate (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 X509Certificate (byte[] rawData, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
public X509Certificate (byte[] rawData, string password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<System.Obsolete("Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.", DiagnosticId="SYSLIB0057", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (rawData As Byte(), password As String, keyStorageFlags As X509KeyStorageFlags)
參數
- rawData
- Byte[]
位元組陣列,包含來自 X.509 憑證的資料。
- password
- String
存取 X.509 憑證資料所需的密碼。
- keyStorageFlags
- X509KeyStorageFlags
列舉值的位元組合,會控制匯入憑證的位置和方式。
- 屬性
例外狀況
備註
這個建構函式會使用位元組數位、存取憑證數據所需的密碼,以及密鑰記憶體旗標來建立新的 X509Certificate 物件。 使用正確的密碼呼叫此建構函式會解密私鑰,並將它儲存至 Microsoft 密碼編譯 API 密碼編譯服務提供者 (CSP) 。
值 X509KeyStorageFlags 可用來控制私鑰的匯入位置及方式。
ASN.1 DER 是唯一此類別支援的憑證格式。
重要
絕對不要在原始程式碼內硬式編碼密碼。 使用 Ildasm.exe (IL 反組譯程式) 、十六進位編輯器,或在文本編輯器中開啟元件,例如 Notepad.exe,即可從元件擷取硬式編碼密碼。
如果您藉由指定的 rawData
PKCS7 簽署檔案存放區來建立X509Certificate憑證,則會X509Certificate針對簽署存放區的憑證建立 ,而不是針對存放區內的任何憑證建立。
適用於
X509Certificate(String, SecureString, X509KeyStorageFlags)
警告
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
重要
此 API 不符合 CLS 規範。
使用憑證檔名、密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。
public:
X509Certificate(System::String ^ fileName, System::Security::SecureString ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
public X509Certificate (string fileName, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate (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 X509Certificate (string fileName, System.Security.SecureString? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
public X509Certificate (string fileName, System.Security.SecureString password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
public X509Certificate (string fileName, System.Security.SecureString password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[<System.CLSCompliant(false)>]
new System.Security.Cryptography.X509Certificates.X509Certificate : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.CLSCompliant(false)>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate
[<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.X509Certificate : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate
new System.Security.Cryptography.X509Certificates.X509Certificate : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (fileName As String, password As SecureString, keyStorageFlags As X509KeyStorageFlags)
參數
- fileName
- String
憑證檔的名稱。
- password
- SecureString
存取 X.509 憑證資料所需的密碼。
- keyStorageFlags
- X509KeyStorageFlags
列舉值的位元組合,會控制匯入憑證的位置和方式。
- 屬性
例外狀況
fileName
參數為 null
。
備註
如果您藉由為 指定 PKCS7 簽署的檔案存放區來建立X509Certificate憑證,X509Certificate則會針對簽署存放區的fileName
憑證建立 ,而不是針對存放區中的任何憑證建立 。
適用於
X509Certificate(String, String, X509KeyStorageFlags)
警告
Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.
使用 PKCS7 已簽署檔案、用於存取憑證的密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。
public:
X509Certificate(System::String ^ fileName, System::String ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);
public X509Certificate (string fileName, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public X509Certificate (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 X509Certificate (string fileName, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
public X509Certificate (string fileName, string password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
new System.Security.Cryptography.X509Certificates.X509Certificate : string * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : string * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<System.Obsolete("Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.", DiagnosticId="SYSLIB0057", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Security.Cryptography.X509Certificates.X509Certificate : string * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (fileName As String, password As String, keyStorageFlags As X509KeyStorageFlags)
參數
- fileName
- String
PKCS7 已簽署檔案的名稱。
- password
- String
存取 X.509 憑證資料所需的密碼。
- keyStorageFlags
- X509KeyStorageFlags
列舉值的位元組合,會控制匯入憑證的位置和方式。
- 屬性
例外狀況
fileName
參數為 null
。
備註
如果您藉由為 指定 PKCS7 簽署的檔案存放區來建立X509Certificate憑證,X509Certificate則會針對簽署存放區的fileName
憑證建立 ,而不是針對存放區中的任何憑證建立 。