# 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](https://download.lucee.org/#17AB52DE-B300-A94B-E058FC978BE4542D)

```
HKDFExpand( algorithm=string, prk=any, info=any, outputLength=numeric );
```

**Returns:** binary

# Arguments

| Argument | Type | Required | Description | Default |
|----------|------|----------|-------------|---------|
| algorithm | string | Yes | Hash algorithm: SHA256, SHA384, or SHA512 |  |
| prk | any | Yes | Pseudo-random key from HKDFExtract |  |
| info | any | Yes | Context/application info (can be empty string or null) |  |
| outputLength | numeric | Yes | Number of bytes to derive |  |

# Examples

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







# Categories

[Cryptography](../../categories/crypto.md)

# See Also

[GenerateHKDFKey()](generatehkdfkey.md), [HKDFExtract()](hkdfextract.md)