Share via


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 () 的包装器,旨在提供与使用加密 API 的应用程序的互操作性。

如果 参数 keySize 设置为 0 位,则使用指定算法的默认密钥大小。

适用于

另请参阅