Crypt::KeyDerivation - PBKDF1, PBKDF2 and HKDF key derivation functions
| Use Case | Command | Description |
|---|---|---|
| đ PBKDF1 key derivation | pbkdf1($password, $salt, $iter, $hash, $len) | Derive key using PBKDF1 (PKCS#5 v2.0) â use with caution |
| đ PBKDF2 key derivation | pbkdf2($password, $salt, $iter, $hash, $len) | Derive key using PBKDF2 (PKCS#5 v2.0) â recommended |
| đ HKDF key derivation | hkdf($password, $salt, $hash, $len, $info) | Derive key using HKDF (RFC 5869) |
| đ HKDF extract | hkdf_extract($password, $salt, $hash) | Extract pseudorandom key from input keying material |
| đ HKDF expand | hkdf_expand($prk, $hash, $len, $info) | Expand pseudorandom key to desired length |
use Crypt::KeyDerivation ':all';
### PBKDF1/2
$derived_key1 = pbkdf1($password, $salt, $iteration_count, $hash_name, $len);
$derived_key2 = pbkdf2($password, $salt, $iteration_count, $hash_name, $len);
### HKDF & co.
$derived_key3 = hkdf($keying_material, $salt, $hash_name, $len, $info);
$prk = hkdf_extract($keying_material, $salt, $hash_name);
$okm1 = hkdf_expand($prk, $hash_name, $len, $info);
Provides an interface to Key derivation functions:
BEWARE: if you are not sure, do not use pbkdf1 but rather choose pbkdf2.
$derived_key = pbkdf1($password, $salt, $iteration_count, $hash_name, $len);
#or
$derived_key = pbkdf1($password, $salt, $iteration_count, $hash_name);
#or
$derived_key = pbkdf1($password, $salt, $iteration_count);
#or
$derived_key = pbkdf1($password, $salt);
# $password ......... đ input keying material (password)
# $salt ............. đ§ salt/nonce (expected length: 8)
# $iteration_count .. đ optional, DEFAULT: 5000
# $hash_name ........ đ optional, DEFAULT: 'SHA256'
# $len .............. đ optional, derived key len, DEFAULT: 32
$derived_key = pbkdf2($password, $salt, $iteration_count, $hash_name, $len);
#or
$derived_key = pbkdf2($password, $salt, $iteration_count, $hash_name);
#or
$derived_key = pbkdf2($password, $salt, $iteration_count);
#or
$derived_key = pbkdf2($password, $salt);
# $password ......... đ input keying material (password)
# $salt ............. đ§ salt/nonce
# $iteration_count .. đ optional, DEFAULT: 5000
# $hash_name ........ đ optional, DEFAULT: 'SHA256'
# $len .............. đ optional, derived key len, DEFAULT: 32
$okm2 = hkdf($password, $salt, $hash_name, $len, $info);
#or
$okm2 = hkdf($password, $salt, $hash_name, $len);
#or
$okm2 = hkdf($password, $salt, $hash_name);
#or
$okm2 = hkdf($password, $salt);
# $password ... đ input keying material (password)
# $salt ....... đ§ salt/nonce, if undef defaults to HashLen zero octets
# $hash_name .. đ optional, DEFAULT: 'SHA256'
# $len ........ đ optional, derived key len, DEFAULT: 32
# $info ....... âšī¸ optional context and application specific information, DEFAULT: ''
$prk = hkdf_extract($password, $salt, $hash_name);
#or
$prk = hkdf_extract($password, $salt, $hash_name);
# $password ... đ input keying material (password)
# $salt ....... đ§ salt/nonce, if undef defaults to HashLen zero octets
# $hash_name .. đ optional, DEFAULT: 'SHA256'
$okm = hkdf_expand($pseudokey, $hash_name, $len, $info);
#or
$okm = hkdf_expand($pseudokey, $hash_name, $len);
#or
$okm = hkdf_expand($pseudokey, $hash_name);
#or
$okm = hkdf_expand($pseudokey);
# $pseudokey .. đ input keying material
# $hash_name .. đ optional, DEFAULT: 'SHA256'
# $len ........ đ optional, derived key len, DEFAULT: 32
# $info ....... âšī¸ optional context and application specific information, DEFAULT: ''
perl v5.34.0 2022-02-06 Crypt::KeyDerivation(3pm)
Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-24 05:05 @216.73.216.102
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)