Uredi

Deli z drugimi prek


PasswordDeriveBytes.CryptDeriveKey(String, String, Int32, Byte[]) Method

Definition

Derives a cryptographic key from the PasswordDeriveBytes object.

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

Parameters

algname
String

The algorithm name for which to derive the key.

alghashname
String

The hash algorithm name to use to derive the key.

keySize
Int32

The size of the key, in bits, to derive.

rgbIV
Byte[]

The initialization vector (IV) to use to derive the key.

Returns

Byte[]

The derived key.

Attributes

Exceptions

The keySize parameter is incorrect.

-or-

The cryptographic service provider (CSP) cannot be acquired.

-or-

The algname parameter is not a valid algorithm name.

-or-

The alghashname parameter is not a valid hash algorithm name.

Examples

This code example is part of a larger example provided for the PasswordDeriveBytes class.

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

Remarks

This function is a wrapper for the Crypto API function CryptDeriveKey(), and is intended to offer interoperability with applications using the Crypto API.

If the keySize parameter is set to 0 bits, the default key size for the specified algorithm is used.

Applies to

See also