Encoding & cryptographyReference
crypt.hmac
Calculate an HMAC-SHA256 authentication code.
Details#
Calculate an HMAC-SHA256 authentication code. Base64-encoded 32-byte HMAC. Unsupported algorithms or provider failure raise errors.
Signature#
crypt.hmac(key: string, data: string, algorithm: string?): stringParameters#
| Parameter | Type | Description |
|---|---|---|
key | string | Raw key bytes, not an implicitly decoded Base64 key. |
data | string | Raw message bytes. |
algorithmoptional | string | Only sha256 is supported, case-insensitively; default sha256. |
Returns#
Base64-encoded 32-byte HMAC. Unsupported algorithms or provider failure raise errors.
Examples#
Local example
local key = crypt.random(32)
local tag = crypt.hmac(key, "Local message")
print(#crypt.base64decode(tag)) -- 32