CryptoSys PKI Pro Manual

Pbe.Kdf2(Int32, Byte[], Byte[], Int32, HashAlgorithm) Method

Derive a key of any length from a password using the PBKDF2 algorithm from PKCS #5 v2.1.

Syntax

[C#]
public static byte[] Kdf2(
   int dkLen,
   byte[] pwdBytes,
   byte[] salt,
   int count,
   HashAlgorithm hashAlg = HashAlgorithm.Sha1 
)
[VB]
Public Shared Function Kdf2 (
   dkLen As Integer,
   pwdBytes As Byte(),
   salt As Byte(),
   count As Integer,
   Optional hashAlg As HashAlgorithm = HashAlgorithm.Sha1 
) As Byte()

Parameters

dkLen  Int32
Required length of key in bytes
pwdBytes  Byte
Password in byte format
salt  Byte
Salt in byte format
count  Int32
Iteration count
hashAlg  HashAlgorithm  (Optional)
Hash algorithm to use in HMAC PRF (default is SHA-1)

Return Value

Byte
Key in byte[] format

Example

// Use PBKDF2 with SHA-256 hash function to derive 192-bit key
// convert password string to bytes
byte[] pwd = System.Text.Encoding.Default.GetBytes("password");
// make a salt
byte[] salt = new byte[] { 0x78, 0x57, 0x8e, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
int n = 24;
byte[] key = Pbe.Kdf2(n, pwd, salt, 2048, HashAlgorithm.Sha256);
Console.WriteLine("Key({0})={1}", n * 8, key.ToHex());
// Key(192)=97B5A91D35AF542324881315C4F849E327C4707D1BC9D322

See Also

VB6/C equivalent: PBE_Kdf2

[Contents] [Index]

[PREV: Ocsp.ReadResponse Method...]   [Contents]   [Index]   
   [NEXT: Pbe.Kdf2(Int32, String, String, Int32, HashAlgorithm) Method...]

Copyright © 2004-26 D.I. Management Services Pty Ltd t/a CryptoSys. All rights reserved. Generated 2026-09-21T05:59:39Z.