Expand description
Code related to HMAC
Functions
sourceexportKey
exportKey
source(format: KeyFormat, key: HmacCryptoKey): Promise<JsonWebKey | ArrayBuffer>
(format: KeyFormat, key: HmacCryptoKey): Promise<JsonWebKey | ArrayBuffer>
Export an HMAC key into the specified format
example
const jwk = await HMAC.exportKey("jwk", key.self);
example
const jwk = await key.exportKey("jwk");
Parameters
format: KeyFormat
key: HmacCryptoKey
Returns Promise<JsonWebKey | ArrayBuffer>
sourcegenerateKey
generateKey
source(algorithm?: Omit<EnforcedHmacKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<HmacProxiedCryptoKey>
(algorithm?: Omit<EnforcedHmacKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<HmacProxiedCryptoKey>
Generate a new HMAC key
example
const key = await HMAC.generateKey();
Parameters
algorithm: Omit<EnforcedHmacKeyGenParams, "name"> = { hash: SHA.Variant.SHA_512, }
extractable: boolean = true
Optional keyUsages: KeyUsage[]
Returns Promise<HmacProxiedCryptoKey>
sourceimportKey
importKey
source(format: KeyFormat, key: BufferSource | JsonWebKey, algorithm: Omit<EnforcedHmacImportParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<HmacProxiedCryptoKey>
(format: KeyFormat, key: BufferSource | JsonWebKey, algorithm: Omit<EnforcedHmacImportParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<HmacProxiedCryptoKey>
Import an HMAC key from the specified format
example
const key = await HMAC.importKey("jwk", jwk, {hash: "SHA-512"});
Parameters
format: KeyFormat
key: BufferSource | JsonWebKey
algorithm: Omit<EnforcedHmacImportParams, "name">
extractable: boolean = true
Optional keyUsages: KeyUsage[]
Returns Promise<HmacProxiedCryptoKey>
sourcesign
sign
source(key: HmacCryptoKey, data: BufferSource): Promise<ArrayBuffer>
(key: HmacCryptoKey, data: BufferSource): Promise<ArrayBuffer>
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);
Parameters
key: HmacCryptoKey
data: BufferSource
Returns Promise<ArrayBuffer>
sourceverify
verify
source(key: HmacCryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>
(key: HmacCryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>
Verify a given signature
example
const isVerified = await HMAC.verify(key, signature, message);
example
const isVerified = await key.verify(signature, message);
Parameters
key: HmacCryptoKey
signature: BufferSource
data: BufferSource