Key Derivation
This feature allows you to derive a key from input key material using the HKDF algorithm. The code sample demonstrates how to use the HKDF class with SHA-256 as the hash function to derive a 32-byte key.
const { HKDF } = require('@stablelib/hkdf');
const { SHA256 } = require('@stablelib/sha256');
const inputKeyMaterial = new Uint8Array([0x00, 0x01, 0x02, 0x03]);
const salt = new Uint8Array([0x04, 0x05, 0x06, 0x07]);
const info = new Uint8Array([0x08, 0x09, 0x0A, 0x0B]);
const hkdf = new HKDF(SHA256, inputKeyMaterial, salt, info);
const derivedKey = hkdf.expand(32); // Derive a 32-byte key
console.log(derivedKey);