HKDFExpand()
Second step of two-phase key derivation: expands an intermediate key (from HKDFExtract) into one or more output keys.
Use different info strings to derive separate keys for different purposes (e.g. encryption vs authentication).
Requires Extension: Crypto Extension
HKDFExpand( algorithm=string, prk=any, info=any, outputLength=numeric );
Returns: binary
| Argument | Description |
|---|---|
|
algorithm
string,
required
|
edit
Hash algorithm: SHA256, SHA384, or SHA512 |
|
prk
any,
required
|
edit
Pseudo-random key from HKDFExtract |
|
info
any,
required
|
edit
Context/application info (can be empty string or null) |
|
outputLength
numeric,
required
|
edit
Number of bytes to derive |
Examples
edit// HKDFExpand is the second phase of HKDF: it expands a pseudorandom key (PRK)
// into one or more output keys. Use different "info" strings to derive separate keys.
// First, extract a PRK from your secret
prk = HKDFExtract( "SHA256", "salt", "master-secret" );
// Then expand into multiple keys for different purposes
encKey = HKDFExpand( "SHA256", prk, "encryption key", 32 ); // 32 bytes for AES-256
authKey = HKDFExpand( "SHA256", prk, "authentication key", 32 ); // 32 bytes for HMAC
ivBytes = HKDFExpand( "SHA256", prk, "iv", 16 ); // 16 bytes for AES IV
// Each key is different because the "info" string is different
// But they're all deterministically derived from the same master secret
See also
- Cryptography
- GenerateHKDFKey()
- HKDFExtract()
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)