Expand description

Code related to HKDF

Functions

Derive a number bits with a given key material

example
const salt = await Random.Salt.generate();
const info = await Random.getValues(6);
const bits = await HKDF.deriveBits(
{ salt, info, hash: "SHA-512" },
keyMaterial,
128
);
example
const salt = await Random.Salt.generate();
const info = await Random.getValues(6);
const bits = await keyMaterial.deriveBits(
{ salt, info, hash: "SHA-512" },
128
);

Derive a shared key from HKDF key material

example
const hmacParams: params.EnforcedHmacKeyGenParams = {
name: Authentication.Alg.Code.HMAC,
hash: SHA.Alg.Variant.SHA_512,
length: 512,
};
const salt = await Random.Salt.generate();
const info = await Random.getValues(6);
let key = await HKDF.deriveKey(
{ salt, info, hash: "SHA-512" },
keyMaterial,
hmacParams
);
example
const hmacParams: params.EnforcedHmacKeyGenParams = {
name: Authentication.Alg.Code.HMAC,
hash: SHA.Alg.Variant.SHA_512,
length: 512,
};
const salt = await Random.Salt.generate();
const info = await Random.getValues(6);
let key = await keyMaterial.deriveKey(
{ salt, info, hash: "SHA-512" },
hmacParams
);

Generate key material for deriving

example
const keyMaterial = await HKDF.generateKeyMaterial("raw", new TextEncoder().encode("lots_of_entropy"));