Skip to content
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#

Luau
crypt.hmac(key: string, data: string, algorithm: string?): string

Parameters#

ParameterTypeDescription
keystringRaw key bytes, not an implicitly decoded Base64 key.
datastringRaw message bytes.
algorithmoptionalstringOnly sha256 is supported, case-insensitively; default sha256.

Returns#

Base64-encoded 32-byte HMAC. Unsupported algorithms or provider failure raise errors.

Examples#

Local example

Luau
local key = crypt.random(32)
local tag = crypt.hmac(key, "Local message")
print(#crypt.base64decode(tag)) -- 32