CryptoSys PKI Pro Manual

Pbe.Kdf2(Int32, String, String, Int32, HashAlgorithm) Method

Derive a key in hex format of any length from a password with the salt in hex format.

Syntax

[C#]
public static string Kdf2(
   int dkLen,
   string pwdStr,
   string saltHex,
   int count,
   HashAlgorithm hashAlg = HashAlgorithm.Sha1 
)
[VB]
Public Shared Function Kdf2 (
   dkLen As Integer,
   pwdStr As String,
   saltHex As String,
   count As Integer,
   Optional hashAlg As HashAlgorithm = HashAlgorithm.Sha1 
) As String

Parameters

dkLen  Int32
Required length of key in bytes
pwdStr  String
Password
saltHex  String
Salt in hex format
count  Int32
Iteration count
hashAlg  HashAlgorithm  (Optional)
Hash algorithm to use in HMAC PRF (default is SHA-1)

Return Value

String
Key in hex format

Example

string saltHex = "78578e5a5d63cb06";
int n = 24;
string keyStr = Pbe.Kdf2(n, "password", saltHex, 2048, HashAlgorithm.Sha256);
Debug.Assert(keyStr.Length > 0, "ERROR with PbeKdf2/Hex");
Console.WriteLine("Key({0})={1}", n * 8, keyStr);
// Key(192)=97B5A91D35AF542324881315C4F849E327C4707D1BC9D322

See Also

VB6/C equivalent: PBE_Kdf2Hex

[Contents] [Index]

[PREV: Pbe.Kdf2(Int32, Byte, Byte, Int32, HashAlgorithm) Method...]   [Contents]   [Index]   
   [NEXT: Pbe.Scrypt(Int32, Byte, Byte, Int32, Int32, Int32) Method...]

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