X509Certificate 建構函式

定義

初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class.

多載

X509Certificate()

初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class.

X509Certificate(String, SecureString, X509KeyStorageFlags)

使用憑證檔名、密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using a certificate file name, a password, and a key storage flag.

X509Certificate(Byte[], String, X509KeyStorageFlags)

使用位元組陣列、密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using a byte array, a password, and a key storage flag.

X509Certificate(Byte[], SecureString, X509KeyStorageFlags)

使用位元組陣列、密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using a byte array, a password, and a key storage flag.

X509Certificate(String, String)

使用 PKCS7 已簽署檔案和用於存取憑證的密碼,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using the name of a PKCS7 signed file and a password to access the certificate.

X509Certificate(String, SecureString)

使用憑證檔名和密碼,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using a certificate file name and a password.

X509Certificate(SerializationInfo, StreamingContext)

使用 X509Certificate 物件和 SerializationInfo 結構,初始化 StreamingContext 類別的新執行個體。Initializes a new instance of the X509Certificate class using a SerializationInfo object and a StreamingContext structure.

X509Certificate(String, String, X509KeyStorageFlags)

使用 PKCS7 已簽署檔案、用於存取憑證的密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using the name of a PKCS7 signed file, a password to access the certificate, and a key storage flag.

X509Certificate(Byte[], SecureString)

使用位元組陣列和密碼,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using a byte array and a password.

X509Certificate(String)

使用 PKCS7 已簽署檔案的名稱,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using the name of a PKCS7 signed file.

X509Certificate(X509Certificate)

使用另一個 X509Certificate 類別,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using another X509Certificate class.

X509Certificate(IntPtr)

使用 Unmanaged PCCERT_CONTEXT 結構的控制代碼,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using a handle to an unmanaged PCCERT_CONTEXT structure.

X509Certificate(Byte[])

初始化 X509Certificate 類別的新執行個體 (這個類別是在表示 X.509v3 憑證的位元組序列中定義的)。Initializes a new instance of the X509Certificate class defined from a sequence of bytes representing an X.509v3 certificate.

X509Certificate(Byte[], String)

使用位元組陣列和密碼,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using a byte array and a password.

X509Certificate()

初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class.

public:
 X509Certificate();
public X509Certificate ();
Public Sub New ()

備註

Asn.1 DER 是此類別唯一支援的憑證格式。ASN.1 DER is the only certificate format supported by this class.

X509Certificate(String, SecureString, X509KeyStorageFlags)

重要

此 API 不符合 CLS 規範。

使用憑證檔名、密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using a certificate file name, a password, and a key storage flag.

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);
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

憑證檔的名稱。The name of a certificate file.

password
SecureString

存取 X.509 憑證資料所需的密碼。The password required to access the X.509 certificate data.

keyStorageFlags
X509KeyStorageFlags

列舉值的位元組合,會控制匯入憑證的位置和方式。A bitwise combination of the enumeration values that control where and how to import the certificate.

屬性

例外狀況

此憑證發生錯誤。An error with the certificate occurs. 例如:For example:

- 憑證檔案不存在。- The certificate file does not exist.

- 憑證無效。- The certificate is invalid.

- 憑證的密碼不正確。- The certificate's password is incorrect.

fileName 參數為 nullThe fileName parameter is null.

備註

如果您藉由指定 fileName的 PKCS7 已簽署檔案存放區來建立 X509Certificate 憑證,則會針對簽署存放區的憑證建立 X509Certificate,而不是針對存放區中的任何憑證。If you create an X509Certificate certificate by specifying a PKCS7 signed file store for fileName, the X509Certificate is created for the certificate that signed the store rather than for any of the certificates within the store.

安全性

FileIOPermission
讀取 fileName 參數所描述之檔案的許可權。for permission to read the file described by the fileName parameter. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: ReadAssociated enumeration: Read

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

X509Certificate(Byte[], String, X509KeyStorageFlags)

使用位元組陣列、密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using a byte array, a password, and a key storage flag.

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);
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 憑證的資料。A byte array containing data from an X.509 certificate.

password
String

存取 X.509 憑證資料所需的密碼。The password required to access the X.509 certificate data.

keyStorageFlags
X509KeyStorageFlags

列舉值的位元組合,會控制匯入憑證的位置和方式。A bitwise combination of the enumeration values that control where and how to import the certificate.

例外狀況

此憑證發生錯誤。An error with the certificate occurs. 例如:For example:

- 憑證檔案不存在。- The certificate file does not exist.

- 憑證無效。- The certificate is invalid.

- 憑證的密碼不正確。- The certificate's password is incorrect.

rawData 參數為 nullThe rawData parameter is null.

-或--or- rawData 參數的長度為 0。The length of the rawData parameter is 0.

備註

此函式會使用位元組陣列、存取憑證資料所需的密碼,以及金鑰儲存旗標,來建立新的 X509Certificate 物件。This constructor creates a new X509Certificate object using a byte array, a password that is needed to access the certificate data, and a key storage flag. 以正確的密碼呼叫此函式會將私密金鑰解密,並將其儲存至 Microsoft 密碼編譯服務提供者(CSP)。Calling this constructor with the correct password decrypts the private key and saves it to a Microsoft Cryptographic API Cryptographic Service Provider (CSP).

X509KeyStorageFlags 值可用於控制匯入私密金鑰的位置和方式。The X509KeyStorageFlags value can be used to control where and how the private key is imported.

Asn.1 DER 是此類別唯一支援的憑證格式。ASN.1 DER is the only certificate format supported by this class.

重要

絕對不要在原始程式碼中將密碼硬編碼。Never hard code a password within your source code. 您可以使用 tlbimp.exe (IL解譯器)、十六進位編輯器,或直接在文字編輯器(如 notepad.exe)中開啟元件,從元件中取出硬式編碼密碼。Hard-coded passwords can be retrieved from an assembly using the Ildasm.exe (IL Disassembler), a hex editor, or by simply opening the assembly in a text editor such as Notepad.exe.

如果您藉由指定 rawData的 PKCS7 已簽署檔案存放區來建立 X509Certificate 憑證,則會針對簽署存放區的憑證建立 X509Certificate,而不是針對存放區中的任何憑證。If you create an X509Certificate certificate by specifying a PKCS7 signed file store for rawData, the X509Certificate is created for the certificate that signed the store rather than for any of the certificates within the store.

安全性

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

X509Certificate(Byte[], SecureString, X509KeyStorageFlags)

重要

此 API 不符合 CLS 規範。

使用位元組陣列、密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using a byte array, a password, and a key storage flag.

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);
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 憑證的資料。A byte array that contains data from an X.509 certificate.

password
SecureString

存取 X.509 憑證資料所需的密碼。The password required to access the X.509 certificate data.

keyStorageFlags
X509KeyStorageFlags

列舉值的位元組合,會控制匯入憑證的位置和方式。A bitwise combination of the enumeration values that control where and how to import the certificate.

屬性

例外狀況

此憑證發生錯誤。An error with the certificate occurs. 例如:For example:

- 憑證檔案不存在。- The certificate file does not exist.

- 憑證無效。- The certificate is invalid.

- 憑證的密碼不正確。- The certificate's password is incorrect.

rawData 參數為 nullThe rawData parameter is null.

-或--or- rawData 參數的長度為 0。The length of the rawData parameter is 0.

備註

以正確的密碼呼叫此函式會將私密金鑰解密,並將其儲存至 Microsoft 密碼編譯服務提供者(CSP)。Calling this constructor with the correct password decrypts the private key and saves it to a Microsoft Cryptographic API Cryptographic Service Provider (CSP).

Asn.1 DER 是此類別唯一支援的憑證格式。ASN.1 DER is the only certificate format supported by this class.

重要

絕對不要在原始程式碼中將密碼硬編碼。Never hard code a password within your source code. 您可以使用 tlbimp.exe (IL解譯器)、十六進位編輯器,或直接在文字編輯器(如 notepad.exe)中開啟元件,從元件中取出硬式編碼密碼。Hard-coded passwords can be retrieved from an assembly using the Ildasm.exe (IL Disassembler), a hex editor, or by simply opening the assembly in a text editor such as Notepad.exe.

如果您藉由指定 rawData的 PKCS7 已簽署檔案存放區來建立 X509Certificate 憑證,則會針對簽署存放區的憑證建立 X509Certificate,而不是針對存放區中的任何憑證。If you create an X509Certificate certificate by specifying a PKCS7 signed file store for rawData, the X509Certificate is created for the certificate that signed the store rather than for any of the certificates within the store.

安全性

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

X509Certificate(String, String)

使用 PKCS7 已簽署檔案和用於存取憑證的密碼,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using the name of a PKCS7 signed file and a password to access the certificate.

public:
 X509Certificate(System::String ^ fileName, System::String ^ password);
public X509Certificate (string fileName, string password);
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 已簽署檔案的名稱。The name of a PKCS7 signed file.

password
String

存取 X.509 憑證資料所需的密碼。The password required to access the X.509 certificate data.

例外狀況

此憑證發生錯誤。An error with the certificate occurs. 例如:For example:

- 憑證檔案不存在。- The certificate file does not exist.

- 憑證無效。- The certificate is invalid.

- 憑證的密碼不正確。- The certificate's password is incorrect.

fileName 參數為 nullThe fileName parameter is null.

備註

Asn.1 DER 是此類別唯一支援的憑證格式。ASN.1 DER is the only certificate format supported by this class. 以正確的密碼呼叫此函式會將私密金鑰解密,並將其儲存至金鑰容器。Calling this constructor with the correct password decrypts the private key and saves it to a key container.

如果您藉由指定 fileName的 PKCS7 已簽署檔案存放區來建立 X509Certificate 憑證,則會針對簽署存放區的憑證建立 X509Certificate,而不是針對存放區中的任何憑證。If you create an X509Certificate certificate by specifying a PKCS7 signed file store for fileName, the X509Certificate is created for the certificate that signed the store rather than for any of the certificates within the store.

安全性

FileIOPermission
讀取 fileName 參數所描述之檔案的許可權。for permission to read the file described by the fileName parameter. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: ReadAssociated enumeration: Read

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

X509Certificate(String, SecureString)

重要

此 API 不符合 CLS 規範。

使用憑證檔名和密碼,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using a certificate file name and a password.

public:
 X509Certificate(System::String ^ fileName, System::Security::SecureString ^ password);
[System.CLSCompliant(false)]
public X509Certificate (string fileName, System.Security.SecureString password);
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

憑證檔的名稱。The name of a certificate file.

password
SecureString

存取 X.509 憑證資料所需的密碼。The password required to access the X.509 certificate data.

屬性

例外狀況

此憑證發生錯誤。An error with the certificate occurs. 例如:For example:

- 憑證檔案不存在。- The certificate file does not exist.

- 憑證無效。- The certificate is invalid.

- 憑證的密碼不正確。- The certificate's password is incorrect.

fileName 參數為 nullThe fileName parameter is null.

備註

Asn.1 DER 是此類別唯一支援的憑證格式。ASN.1 DER is the only certificate format supported by this class. 以正確的密碼呼叫此函式會將私密金鑰解密,並將其儲存至金鑰容器。Calling this constructor with the correct password decrypts the private key and saves it to a key container.

重要

絕對不要在原始程式碼中將密碼硬編碼。Never hard code a password within your source code. 您可以使用 tlbimp.exe (IL解譯器)、十六進位編輯器,或直接在文字編輯器(如 notepad.exe)中開啟元件,從元件中取出硬式編碼密碼。Hard-coded passwords can be retrieved from an assembly using the Ildasm.exe (IL Disassembler), a hex editor, or by simply opening the assembly in a text editor such as Notepad.exe.

如果您藉由指定 fileName的 PKCS7 已簽署檔案存放區來建立 X509Certificate 憑證,則會針對簽署存放區的憑證建立 X509Certificate,而不是針對存放區中的任何憑證。If you create an X509Certificate certificate by specifying a PKCS7 signed file store for fileName, the X509Certificate is created for the certificate that signed the store rather than for any of the certificates within the store.

安全性

FileIOPermission
讀取 fileName 參數所描述之檔案的許可權。for permission to read the file described by the fileName parameter. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: ReadAssociated enumeration: Read

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

X509Certificate(SerializationInfo, StreamingContext)

使用 X509Certificate 物件和 SerializationInfo 結構,初始化 StreamingContext 類別的新執行個體。Initializes a new instance of the X509Certificate class using a SerializationInfo object and a StreamingContext structure.

public:
 X509Certificate(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
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
Public Sub New (info As SerializationInfo, context As StreamingContext)

參數

info
SerializationInfo

SerializationInfo 物件,描述序列化 (Serialization) 資訊。A SerializationInfo object that describes serialization information.

context
StreamingContext

StreamingContext 結構,描述應如何執行序列化。A StreamingContext structure that describes how serialization should be performed.

例外狀況

此憑證發生錯誤。An error with the certificate occurs. 例如:For example:

- 憑證檔案不存在。- The certificate file does not exist.

- 憑證無效。- The certificate is invalid.

- 憑證的密碼不正確。- The certificate's password is incorrect.

X509Certificate(String, String, X509KeyStorageFlags)

使用 PKCS7 已簽署檔案、用於存取憑證的密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using the name of a PKCS7 signed file, a password to access the certificate, and a key storage flag.

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);
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 已簽署檔案的名稱。The name of a PKCS7 signed file.

password
String

存取 X.509 憑證資料所需的密碼。The password required to access the X.509 certificate data.

keyStorageFlags
X509KeyStorageFlags

列舉值的位元組合,會控制匯入憑證的位置和方式。A bitwise combination of the enumeration values that control where and how to import the certificate.

例外狀況

此憑證發生錯誤。An error with the certificate occurs. 例如:For example:

- 憑證檔案不存在。- The certificate file does not exist.

- 憑證無效。- The certificate is invalid.

- 憑證的密碼不正確。- The certificate's password is incorrect.

fileName 參數為 nullThe fileName parameter is null.

備註

如果您藉由指定 fileName的 PKCS7 已簽署檔案存放區來建立 X509Certificate 憑證,則會針對簽署存放區的憑證建立 X509Certificate,而不是針對存放區中的任何憑證。If you create an X509Certificate certificate by specifying a PKCS7 signed file store for fileName, the X509Certificate is created for the certificate that signed the store rather than for any of the certificates within the store.

安全性

FileIOPermission
讀取 fileName 參數所描述之檔案的許可權。for permission to read the file described by the fileName parameter. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: ReadAssociated enumeration: Read

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

X509Certificate(Byte[], SecureString)

重要

此 API 不符合 CLS 規範。

使用位元組陣列和密碼,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using a byte array and a password.

public:
 X509Certificate(cli::array <System::Byte> ^ rawData, System::Security::SecureString ^ password);
[System.CLSCompliant(false)]
public X509Certificate (byte[] rawData, System.Security.SecureString password);
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 憑證的資料。A byte array that contains data from an X.509 certificate.

password
SecureString

存取 X.509 憑證資料所需的密碼。The password required to access the X.509 certificate data.

屬性

例外狀況

此憑證發生錯誤。An error with the certificate occurs. 例如:For example:

- 憑證檔案不存在。- The certificate file does not exist.

- 憑證無效。- The certificate is invalid.

- 憑證的密碼不正確。- The certificate's password is incorrect.

rawData 參數為 nullThe rawData parameter is null.

-或--or- rawData 參數的長度為 0。The length of the rawData parameter is 0.

備註

Asn.1 DER 是此類別唯一支援的憑證格式。ASN.1 DER is the only certificate format supported by this class.

重要

絕對不要在原始程式碼中將密碼硬編碼。Never hard code a password within your source code. 您可以使用 tlbimp.exe (IL解譯器)、十六進位編輯器,或直接在文字編輯器(如 notepad.exe)中開啟元件,從元件中取出硬式編碼密碼。Hard-coded passwords can be retrieved from an assembly using the Ildasm.exe (IL Disassembler), a hex editor, or by simply opening the assembly in a text editor such as Notepad.exe.

如果您藉由指定 rawData的 PKCS7 已簽署檔案存放區來建立 X509Certificate 憑證,則會針對簽署存放區的憑證建立 X509Certificate,而不是針對存放區中的任何憑證。If you create an X509Certificate certificate by specifying a PKCS7 signed file store for rawData, the X509Certificate is created for the certificate that signed the store rather than for any of the certificates within the store.

安全性

SecurityPermission
提供呼叫非受控碼的能力。for the ability to call unmanaged code. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: UnmanagedCodeAssociated enumeration: UnmanagedCode

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

X509Certificate(String)

使用 PKCS7 已簽署檔案的名稱,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using the name of a PKCS7 signed file.

public:
 X509Certificate(System::String ^ fileName);
public X509Certificate (string fileName);
new System.Security.Cryptography.X509Certificates.X509Certificate : string -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (fileName As String)

參數

fileName
String

PKCS7 已簽署檔案的名稱。The name of a PKCS7 signed file.

例外狀況

此憑證發生錯誤。An error with the certificate occurs. 例如:For example:

- 憑證檔案不存在。- The certificate file does not exist.

- 憑證無效。- The certificate is invalid.

- 憑證的密碼不正確。- The certificate's password is incorrect.

fileName 參數為 nullThe fileName parameter is null.

範例

下列範例會從檔案載入 x.509 憑證、呼叫 ToString 方法,並將結果顯示在主控台中。The following example loads an X.509 certificate from a file, calls the ToString method, and displays the results to the console.

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 是此類別唯一支援的憑證格式。ASN.1 DER is the only certificate format supported by this class.

如果您藉由指定 fileName的 PKCS7 已簽署檔案存放區來建立 X509Certificate 憑證,則會針對簽署存放區的憑證建立 X509Certificate,而不是針對存放區中的任何憑證。If you create an X509Certificate certificate by specifying a PKCS7 signed file store for fileName, the X509Certificate is created for the certificate that signed the store rather than for any of the certificates within the store.

安全性

FileIOPermission
讀取 fileName 參數所描述之檔案的許可權。for permission to read the file described by the fileName parameter. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: ReadAssociated enumeration: Read

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

X509Certificate(X509Certificate)

使用另一個 X509Certificate 類別,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using another X509Certificate class.

public:
 X509Certificate(System::Security::Cryptography::X509Certificates::X509Certificate ^ cert);
public X509Certificate (System.Security.Cryptography.X509Certificates.X509Certificate cert);
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 類別。A X509Certificate class from which to initialize this class.

例外狀況

此憑證發生錯誤。An error with the certificate occurs. 例如:For example:

- 憑證檔案不存在。- The certificate file does not exist.

- 憑證無效。- The certificate is invalid.

- 憑證的密碼不正確。- The certificate's password is incorrect.

cert 參數的值為 nullThe value of the cert parameter is null.

備註

Asn.1 DER 是此類別唯一支援的憑證格式。ASN.1 DER is the only certificate format supported by this class.

X509Certificate(IntPtr)

使用 Unmanaged PCCERT_CONTEXT 結構的控制代碼,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using a handle to an unmanaged PCCERT_CONTEXT structure.

public:
 X509Certificate(IntPtr handle);
[System.Security.SecurityCritical]
public X509Certificate (IntPtr handle);
new System.Security.Cryptography.X509Certificates.X509Certificate : nativeint -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (handle As IntPtr)

參數

handle
IntPtr

Unmanaged PCCERT_CONTEXT 結構的控制代碼。A handle to an unmanaged PCCERT_CONTEXT structure.

屬性

例外狀況

此憑證發生錯誤。An error with the certificate occurs. 例如:For example:

- 憑證檔案不存在。- The certificate file does not exist.

- 憑證無效。- The certificate is invalid.

- 憑證的密碼不正確。- The certificate's password is incorrect.

此控制代碼參數不表示有效的 PCCERT_CONTEXT 結構。The handle parameter does not represent a valid PCCERT_CONTEXT structure.

備註

此函式會使用 Microsoft 密碼編譯 API 憑證內容的控制碼,建立新的 X509Certificate 物件,PCCERT_CONTEXTThis constructor creates a new X509Certificate object using a handle for the Microsoft Cryptographic API certificate context, PCCERT_CONTEXT.

重要

此構造函式會建立憑證內容的複本。This constructor creates a copy of the certificate context. 請勿假設您傳遞給此函式的內容結構是有效的;它可能已發行。Do not assume that the context structure you passed to the constructor is valid; it may have been released. 您可以從 Handle 屬性取得目前 PCCERT_CONTEXT 結構的複本,但它只在 X509Certificate 物件的存留期間有效。You can get a copy of the current PCCERT_CONTEXT structure from the Handle property, but it is valid only during the lifetime of the X509Certificate object.

安全性

SecurityCriticalAttribute
需要完全信任立即呼叫者。requires full trust for the immediate caller. 這個類別無法由部分信任或透明的程式碼使用。This class cannot be used by partially trusted or transparent code.

InheritanceDemand
讓繼承者能夠執行非受控碼。for the ability of inheritors to execute unmanaged code. 相關聯的列舉: UnmanagedCodeAssociated enumeration: UnmanagedCode

X509Certificate(Byte[])

初始化 X509Certificate 類別的新執行個體 (這個類別是在表示 X.509v3 憑證的位元組序列中定義的)。Initializes a new instance of the X509Certificate class defined from a sequence of bytes representing an X.509v3 certificate.

public:
 X509Certificate(cli::array <System::Byte> ^ data);
public X509Certificate (byte[] data);
new System.Security.Cryptography.X509Certificates.X509Certificate : byte[] -> System.Security.Cryptography.X509Certificates.X509Certificate
Public Sub New (data As Byte())

參數

data
Byte[]

位元組陣列,包含來自 X.509 憑證的資料。A byte array containing data from an X.509 certificate.

例外狀況

此憑證發生錯誤。An error with the certificate occurs. 例如:For example:

- 憑證檔案不存在。- The certificate file does not exist.

- 憑證無效。- The certificate is invalid.

- 憑證的密碼不正確。- The certificate's password is incorrect.

rawData 參數為 nullThe rawData parameter is null.

-或--or- rawData 參數的長度為 0。The length of the rawData parameter is 0.

範例

下列範例會將 x.509 憑證檔案載入 X509Certificate 物件中,將憑證匯出為位元組陣列,然後將位元組陣列匯入另一個 X509Certificate 物件。The following example loads an X.509 certificate file into an X509Certificate object, exports the certificate as a byte array, and then imports the byte array into another X509Certificate object.

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 是此類別唯一支援的憑證格式。ASN.1 DER is the only certificate format supported by this class.

如果您藉由指定 data的 PKCS7 已簽署檔案存放區來建立 X509Certificate 憑證,則會針對簽署存放區的憑證建立 X509Certificate,而不是針對存放區中的任何憑證。If you create an X509Certificate certificate by specifying a PKCS7 signed file store for data, the X509Certificate is created for the certificate that signed the store rather than for any of the certificates within the store.

安全性

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

X509Certificate(Byte[], String)

使用位元組陣列和密碼,初始化 X509Certificate 類別的新執行個體。Initializes a new instance of the X509Certificate class using a byte array and a password.

public:
 X509Certificate(cli::array <System::Byte> ^ rawData, System::String ^ password);
public X509Certificate (byte[] rawData, string password);
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 憑證的資料。A byte array containing data from an X.509 certificate.

password
String

存取 X.509 憑證資料所需的密碼。The password required to access the X.509 certificate data.

例外狀況

此憑證發生錯誤。An error with the certificate occurs. 例如:For example:

- 憑證檔案不存在。- The certificate file does not exist.

- 憑證無效。- The certificate is invalid.

- 憑證的密碼不正確。- The certificate's password is incorrect.

rawData 參數為 nullThe rawData parameter is null.

-或--or- rawData 參數的長度為 0。The length of the rawData parameter is 0.

備註

Asn.1 DER 是此類別唯一支援的憑證格式。ASN.1 DER is the only certificate format supported by this class.

重要

絕對不要在原始程式碼中將密碼硬編碼。Never hard code a password within your source code. 您可以使用 tlbimp.exe (IL解譯器)、十六進位編輯器,或直接在文字編輯器(如 notepad.exe)中開啟元件,從元件中取出硬式編碼密碼。Hard-coded passwords can be retrieved from an assembly using the Ildasm.exe (IL Disassembler), a hex editor, or by simply opening the assembly in a text editor such as Notepad.exe.

如果您藉由指定 rawData的 PKCS7 已簽署檔案存放區來建立 X509Certificate 憑證,則會針對簽署存放區的憑證建立 X509Certificate,而不是針對存放區中的任何憑證。If you create an X509Certificate certificate by specifying a PKCS7 signed file store for rawData, the X509Certificate is created for the certificate that signed the store rather than for any of the certificates within the store.

安全性

SecurityPermission
提供呼叫非受控碼的能力。for the ability to call unmanaged code. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: UnmanagedCodeAssociated enumeration: UnmanagedCode

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

適用於