Syntax
crypt.hmac(key: string, data: string, algorithm?: "sha256" | "sha1" | "sha224" | "sha384" | "sha512" | "md5"): stringArguments
| Name | Type | Description |
|---|---|---|
key | string | Key used to authenticate the message. |
data | string | Message or byte string to authenticate. |
algorithm? | "sha256" | "sha1" | "sha224" | "sha384" | "sha512" | "md5" | HMAC algorithm. Defaults to sha256. |
Returns
| Name | Type | Description |
|---|---|---|
digest | string | Base64-encoded HMAC digest. |
Description
Creates a keyed HMAC digest for authenticating a message.
Call it with 3 parameter(s): key, data, algorithm. The argument table explains which values are required and which ones only refine the behavior.
It returns digest (string). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Authenticate a message with a caller-provided key.
local message = "payload"
local key = crypt.generatekey()
local digest = crypt.hmac(key, message, "sha256")
print(digest)