crypto.hkdf
HMAC-based Extract-and-Expand Key Derivation Function library.
Can be called directly as crypto.hkdf( options ), see hkdf.derive.
See RFC 5869 for the algorithm.
Functions
crypto.hkdf.derive | Derives a key using the hkdf algorithm, extract and expand in one step. |
crypto.hkdf.expand | HKDF-Expand step, expands the pseudorandom key into the output keying material (OKM). |
crypto.hkdf.extract | HKDF-Extract step, computes a pseudorandom key (PRK) from the input keying material. |
#crypto.hkdf.derive
function crypto.hkdf.derive(options: hkdf.Options): string
Derives a key using the hkdf algorithm, extract and expand in one step.
Parameters
| Name | Type | Description |
|---|---|---|
options | hkdf.Options |
Returns
| Type | Name | Description |
|---|---|---|
string | hkdf_str | The derived key as a binary string of length bytes. |
#crypto.hkdf.expand
function crypto.hkdf.expand(hash: crypto.HashClass, prk: string, info?: string, length?: integer): string
HKDF-Expand step, expands the pseudorandom key into the output keying material (OKM).
Parameters
| Name | Type | Description |
|---|---|---|
hash | crypto.HashClass | The hash class to use, e.g. crypto.SHA256. |
prk | string | The pseudorandom key, usually the result of hkdf.extract. |
infooptional | string | The optional context and application specific information, default is an empty string. |
lengthoptional | integer | The length of the output keying material in bytes, default is digest_size, must not exceed 255 * digest_size. |
Returns
| Type | Name | Description |
|---|---|---|
string | okm | The output keying material as a binary string of length bytes. |
#crypto.hkdf.extract
function crypto.hkdf.extract(hash: crypto.HashClass, key: string, salt?: string): string
HKDF-Extract step, computes a pseudorandom key (PRK) from the input keying material.
Parameters
| Name | Type | Description |
|---|---|---|
hash | crypto.HashClass | The hash class to use, e.g. crypto.SHA256. |
key | string | The input keying material (IKM). |
saltoptional | string | The optional salt, default is a string of digest_size zero bytes. |
Returns
| Type | Name | Description |
|---|---|---|
string | prk | The pseudorandom key as a binary string of digest_size bytes. |