Edit

Share via


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

Definition

Derives a cryptographic key from the PasswordDeriveBytes object.

C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public byte[] CryptDeriveKey(string? algname, string? alghashname, int keySize, byte[] rgbIV);
C#
public byte[] CryptDeriveKey(string algname, string alghashname, int keySize, byte[] rgbIV);

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.

C#

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

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also