crypt.hmac Synchronous

Compute a keyed message authentication code for a byte string. Use it to authenticate a message with a shared secret key. Unlike an unkeyed hash, reproducing the tag requires the same key as well as the same message.

Syntax
Luau
crypt.hmac(key: string, data: string, algorithm: string) -> string

Parameters

Function parameters
ParameterTypeDescription
keystringRaw authentication key, up to 16 MiB. This is the first argument.
datastringMessage bytes to authenticate, up to 16 MiB.
algorithmstringMD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA3-224, SHA3-256, SHA3-384, SHA3-512, or BLAKE2B. Case and common separator variants are normalized.

Returns

string

The message authentication code encoded as Base64.

Example

Example
Luau
local key = crypt.random(32)
local message = "example status update"
local tag = crypt.hmac(key, message, "SHA256")
print("Base64 authentication tag:", tag)
-- The verifier needs the same raw key, message bytes, and algorithm.
Kawaii documentation