crypt.hmac Synchronous

Authenticate a message with a shared secret. A matching HMAC shows that the same key and message bytes were used, which makes it suitable for checking stored or exchanged data.

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

Parameters

Function parameters
ParameterTypeDescription
keystringRaw shared secret bytes. The key is the first argument and may be up to 16 MiB.
datastringMessage bytes, up to 16 MiB.
algorithmstringDigest algorithm supported by crypt.hash, such as SHA-256.

Returns

string

The message authentication code as Base64 text.

Usage notes

The key is raw text or bytes here, not a Base64 key in the format expected by crypt.encrypt. Keep it private.

Example

Example
Luau
local key = "shared secret for this example"
local message = "approved=true"
local tag = crypt.hmac(key, message, "SHA-256")
print(tag)
assert(tag == crypt.hmac(key, message, "SHA-256"))
Kawaii documentation