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.
Luau
crypt.hmac(key: string, data: string, algorithm: string) -> stringParameters
| Parameter | Type | Description |
|---|---|---|
key | string | Raw shared secret bytes. The key is the first argument and may be up to 16 MiB. |
data | string | Message bytes, up to 16 MiB. |
algorithm | string | Digest algorithm supported by crypt.hash, such as SHA-256. |
Returns
stringThe 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
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"))