PasswordDeriveBytes.CryptDeriveKey(String, String, Int32, Byte[]) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从 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.
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 位,则使用指定算法的默认密钥大小。