hmac
Compute or verify HMAC authentication tags for data with a secret key. Supports multiple hash algorithms, input formats (text/hex/base64), and constant-time verification.
Instructions
Compute or verify an HMAC authentication tag over data with a secret key.
data and key are decoded with input_format / key_format. When
expected is supplied, valid reports a constant-time comparison against the
computed tag (tolerant of case/0x/whitespace in the expected value).
Returns {algorithm, mac, output_format}, plus valid when expected is given.
Example: hmac("msg", "key") -> mac "2d93cbc1be167bcb1637a4a23cbff01a..."
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | Yes | Message to authenticate, decoded via `input_format`. | |
| key | Yes | Secret key, decoded via `key_format`. | |
| algorithm | No | Underlying cryptographic hash (HMAC digestmod): md5/sha1/sha2*/sha3*/blake2*. Default 'sha256'. | sha256 |
| input_format | No | How `data` is decoded to bytes; default 'text'. | text |
| key_format | No | How `key` is decoded to bytes; default 'text'. | text |
| output_format | No | How the tag is rendered (bare hex, no 0x); default 'hex'. | hex |
| expected | No | Expected tag to verify against, in `output_format`; case/`0x`/whitespace tolerated, compared constant-time. Default None skips verification. |