Module hmac

source · []
Expand description

Code related to HMAC

Functions

Export an HMAC key into the specified format

example
const jwk = await HMAC.exportKey("jwk", key.self);
example
const jwk = await key.exportKey("jwk");

Generate a new HMAC key

example
const key = await HMAC.generateKey();

Import an HMAC key from the specified format

example
const key = await HMAC.importKey("jwk", jwk, {hash: "SHA-512"});

Sign a given payload

example
const message = new TextEncoder().encode("a message");
const signature = await HMAC.sign(key.self, message);
const message = new TextEncoder().encode("a message");
const signature = await key.sign(message);

Verify a given signature

example
const isVerified = await HMAC.verify(key, signature, message);
example
const isVerified = await key.verify(signature, message);

Namespaces

Interfaces