RSA.ImportEncryptedPkcs8PrivateKey 方法

定義

多載

ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Int32)

使用位元組型密碼解密之後,從 PKCS#8 EncryptedPrivateKeyInfo 結構匯入公開/私密金鑰組,以取代這個物件的金鑰。Imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a byte-based password, replacing the keys for this object.

ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, ReadOnlySpan<Byte>, Int32)

使用 Char 型密碼解密之後,從 PKCS#8 EncryptedPrivateKeyInfo 結構匯入公開/私密金鑰組,以取代這個物件的金鑰。Imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a char-based password, replacing the keys for this object.

ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Int32)

使用位元組型密碼解密之後,從 PKCS#8 EncryptedPrivateKeyInfo 結構匯入公開/私密金鑰組,以取代這個物件的金鑰。Imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a byte-based password, replacing the keys for this object.

public:
 override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<System::Byte> passwordBytes, ReadOnlySpan<System::Byte> source, [Runtime::InteropServices::Out] int % bytesRead);
public override void ImportEncryptedPkcs8PrivateKey (ReadOnlySpan<byte> passwordBytes, ReadOnlySpan<byte> source, out int bytesRead);
override this.ImportEncryptedPkcs8PrivateKey : ReadOnlySpan<byte> * ReadOnlySpan<byte> * int -> unit
Public Overrides Sub ImportEncryptedPkcs8PrivateKey (passwordBytes As ReadOnlySpan(Of Byte), source As ReadOnlySpan(Of Byte), ByRef bytesRead As Integer)

參數

passwordBytes
ReadOnlySpan<Byte>

解密金鑰內容時要用作密碼的位元組。The bytes to use as a password when decrypting the key material.

source
ReadOnlySpan<Byte>

以 ASN.1-BER 編碼的 PKCS#8 EncryptedPrivateKeyInfo 結構位元組。The bytes of a PKCS#8 EncryptedPrivateKeyInfo structure in the ASN.1-BER encoding.

bytesRead
Int32

當此方法傳回時,會包含一個值,指出讀取自 source 的位元組數。When this method returns, contains a value that indicates the number of bytes read from source. 這個參數會被視為未初始化。This parameter is treated as uninitialized.

例外狀況

密碼不正確。The password is incorrect.

-或--or-

source 的內容指出要套用的金鑰衍生函數 (Key Derivation Function) (KDF) 是舊版 PKCS#12 KDF,這需要 Char 型密碼。The contents of source indicate the Key Derivation Function (KDF) to apply is the legacy PKCS#12 KDF, which requires Char-based passwords.

-或--or-

source 的內容不表示 ASN.1-BER 編碼的 PKCS#8 EncryptedPrivateKeyInfo 結構。The contents of source do not represent an ASN.1-BER-encoded PKCS#8 EncryptedPrivateKeyInfo structure.

-或--or-

source 的內容指出金鑰適用於這個執行個體所表示演算法以外的演算法。The contents of source indicate the key is for an algorithm other than the algorithm represented by this instance.

-或--or-

source 的內容表示金鑰的格式不受支援。The contents of source represent the key in a format that is not supported.

-或--or-

演算法專屬金鑰匯入失敗。The algorithm-specific key import failed.

備註

密碼位元組會直接傳遞至金鑰衍生函式 (KDF 由 EncryptedPrivateKeyInfo 內容所指出的演算法所使用的) 。The password bytes are passed directly into the Key Derivation Function (KDF) used by the algorithm indicated by the EncryptedPrivateKeyInfo contents. 這可讓您在使用 PBKDF2 (密碼型金鑰衍生函式 2) 處理密碼時,使用 UTF-8 以外的文字編碼來與其他系統相容。This enables compatibility with other systems which use a text encoding other than UTF-8 when processing passwords with PBKDF2 (Password-Based Key Derivation Function 2).

這個方法只支援 EncryptedPrivateKeyInfo) 編碼的 binary (BER/CER/DER 編碼。This method only supports the binary (BER/CER/DER) encoding of EncryptedPrivateKeyInfo. 如果值是 Base64 編碼或 PEM 文字格式,呼叫端必須在呼叫這個方法之前,先將內容設定為 Base64。If the value is Base64-encoded or in the PEM text format, the caller must Base64-decode the contents before calling this method.

適用於

ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, ReadOnlySpan<Byte>, Int32)

使用 Char 型密碼解密之後,從 PKCS#8 EncryptedPrivateKeyInfo 結構匯入公開/私密金鑰組,以取代這個物件的金鑰。Imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a char-based password, replacing the keys for this object.

public:
 override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<char> password, ReadOnlySpan<System::Byte> source, [Runtime::InteropServices::Out] int % bytesRead);
public override void ImportEncryptedPkcs8PrivateKey (ReadOnlySpan<char> password, ReadOnlySpan<byte> source, out int bytesRead);
override this.ImportEncryptedPkcs8PrivateKey : ReadOnlySpan<char> * ReadOnlySpan<byte> * int -> unit
Public Overrides Sub ImportEncryptedPkcs8PrivateKey (password As ReadOnlySpan(Of Char), source As ReadOnlySpan(Of Byte), ByRef bytesRead As Integer)

參數

password
ReadOnlySpan<Char>

要用於解密金鑰產製原料的密碼。The password to use for decrypting the key material.

source
ReadOnlySpan<Byte>

以 ASN.1-BER 編碼的 PKCS#8 EncryptedPrivateKeyInfo 結構位元組。The bytes of a PKCS#8 EncryptedPrivateKeyInfo structure in the ASN.1-BER encoding.

bytesRead
Int32

當此方法傳回時,會包含一個值,指出讀取自 source 的位元組數。When this method returns, contains a value that indicates the number of bytes read from source. 這個參數會被視為未初始化。This parameter is treated as uninitialized.

例外狀況

密碼不正確。The password is incorrect.

-或--or-

source 的內容不表示 ASN.1-BER 編碼的 PKCS#8 EncryptedPrivateKeyInfo 結構。The contents of source do not represent an ASN.1-BER-encoded PKCS#8 EncryptedPrivateKeyInfo structure.

-或--or-

source 的內容指出金鑰適用於這個執行個體所表示演算法以外的演算法。The contents of source indicate the key is for an algorithm other than the algorithm represented by this instance.

-或--or-

source 的內容表示金鑰的格式不受支援。The contents of source represent the key in a format that is not supported.

-或--or-

演算法專屬金鑰匯入失敗。The algorithm-specific key import failed.

備註

當的內容 source 指出使用 PBKDF1 (以密碼為基礎的金鑰衍生函式 1) 或 PBKDF2 (密碼型金鑰衍生函式 2) 時,密碼會透過 utf-8 編碼轉換為位元組的演算法。When the contents of source indicate an algorithm that uses PBKDF1 (Password-Based Key Derivation Function 1) or PBKDF2 (Password-Based Key Derivation Function 2), the password is converted to bytes via the UTF-8 encoding.

這個方法只支援 EncryptedPrivateKeyInfo) 編碼的 binary (BER/CER/DER 編碼。This method only supports the binary (BER/CER/DER) encoding of EncryptedPrivateKeyInfo. 如果值是 Base64 編碼或 PEM 文字格式,呼叫端必須在呼叫這個方法之前,先將內容設定為 Base64。If the value is Base64-encoded or in the PEM text format, the caller must Base64-decode the contents before calling this method.

適用於