Expand description
Code related to HKDF
Functions
sourcederiveBits
deriveBits
source(algorithm: Omit<EnforcedHkdfParams, "name">, baseKey: HkdfKeyMaterial, length: number): Promise<ArrayBuffer>
(algorithm: Omit<EnforcedHkdfParams, "name">, baseKey: HkdfKeyMaterial, length: number): Promise<ArrayBuffer>
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
);
Parameters
algorithm: Omit<EnforcedHkdfParams, "name">
baseKey: HkdfKeyMaterial
length: number
Returns Promise<ArrayBuffer>
sourcederiveKey
deriveKey
source(algorithm: Omit<EnforcedHkdfParams, "name">, baseKey: HkdfKeyMaterial, derivedKeyType: EnforcedHmacKeyGenParams | EnforcedAesKeyGenParams, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<HmacCryptoKey | AesCryptoKeys>
(algorithm: Omit<EnforcedHkdfParams, "name">, baseKey: HkdfKeyMaterial, derivedKeyType: EnforcedHmacKeyGenParams | EnforcedAesKeyGenParams, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<HmacCryptoKey | AesCryptoKeys>
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
);
Parameters
algorithm: Omit<EnforcedHkdfParams, "name">
baseKey: HkdfKeyMaterial
derivedKeyType: EnforcedHmacKeyGenParams | EnforcedAesKeyGenParams
Optional extractable: boolean
Optional keyUsages: KeyUsage[]
Returns Promise<HmacCryptoKey | AesCryptoKeys>
sourcegenerateKeyMaterial
generateKeyMaterial
source(format: KeyFormat, key: BufferSource, extractable?: boolean): Promise<HkdfProxiedKeyMaterial>
(format: KeyFormat, key: BufferSource, extractable?: boolean): Promise<HkdfProxiedKeyMaterial>
Generate key material for deriving
example
const keyMaterial = await HKDF.generateKeyMaterial("raw", new TextEncoder().encode("lots_of_entropy"));
Parameters
format: KeyFormat
key: BufferSource
Optional extractable: boolean