🔐 Computes an HMAC-SHA-256 digest of a message with a secret key.

Info

Always returns a `Promise`. Uses the standard Web Crypto API (`crypto.subtle`).

Syntax

TypeScript
import { hmacSHA256 } from '@opentf/std';

hmacSHA256(key: string, message: string): Promise<string>;

Parameters

NameTypeDescription
keystringThe secret key.
messagestringThe message to authenticate.

Returns

A hex-encoded HMAC-SHA-256 digest string (64 characters).

Examples

TypeScript
await hmacSHA256('secret', 'hello')
//=> '88aab3ede8d3adf94d26ab90d3bafd4a2083070c3bcce9c014ee04a443847c0b'
Last updated on
Edit this page