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.
Luau
crypt.hmac(key: string, data: string, algorithm: string) -> stringParameters
| Parameter | Type | Description |
|---|---|---|
key | string | Raw authentication key, up to 16 MiB. This is the first argument. |
data | string | Message bytes to authenticate, up to 16 MiB. |
algorithm | string | MD5, 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
stringThe message authentication code encoded as Base64.
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.