共用方式為


PasswordDeriveBytes.CryptDeriveKey(String, String, Int32, Byte[]) 方法

定義

PasswordDeriveBytes 物件衍生密碼編譯金鑰。

public:
 cli::array <System::Byte> ^ CryptDeriveKey(System::String ^ algname, System::String ^ alghashname, int keySize, cli::array <System::Byte> ^ rgbIV);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public byte[] CryptDeriveKey (string? algname, string? alghashname, int keySize, byte[] rgbIV);
public byte[] CryptDeriveKey (string algname, string alghashname, int keySize, byte[] rgbIV);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
member this.CryptDeriveKey : string * string * int * byte[] -> byte[]
member this.CryptDeriveKey : string * string * int * byte[] -> byte[]
Public Function CryptDeriveKey (algname As String, alghashname As String, keySize As Integer, rgbIV As Byte()) As Byte()

參數

algname
String

用來衍生金鑰的演算法名稱。

alghashname
String

要用來衍生金鑰的雜湊演算法名稱。

keySize
Int32

要衍生的金鑰大小 (以位元為單位)。

rgbIV
Byte[]

用來衍生金鑰的初始化向量 (IV)。

傳回

Byte[]

所衍生金鑰。

屬性

例外狀況

keySize 參數不正確。

-或-

無法取得密碼編譯服務提供者 (CSP)。

-或-

algname 參數不是有效的演算法名稱。

-或-

alghashname 參數不是有效的雜湊演算法名稱。

範例

此程式代碼範例是提供給 類別之較大範例的 PasswordDeriveBytes 一部分。

// Create the key and set it to the Key property
// of the TripleDESCryptoServiceProvider object.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
 cryptoDESProvider->Key = passwordDeriveBytes->CryptDeriveKey
     ("TripleDES", "SHA1", 192, cryptoDESProvider->IV);

// Create the key and set it to the Key property
// of the TripleDESCryptoServiceProvider object.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
tdes.Key = pdb.CryptDeriveKey("TripleDES", "SHA1", 192, tdes.IV);

' Create the key and set it to the Key property
' of the TripleDESCryptoServiceProvider object.
' This example uses the SHA1 algorithm.
' Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
tdes.Key = pdb.CryptDeriveKey("TripleDES", "SHA1", 192, tdes.IV)

備註

此函式是 Crypto API 函式 CryptDeriveKey () 的包裝函式,旨在提供與使用 Crypto API 的應用程式互操作性。

keySize如果參數設定為 0 位,則會使用指定演算法的預設金鑰大小。

適用於

另請參閱