Skip to content

crypto.hmac

Creates a Hash-based Message Authentication Code (HMAC) of the provided data using a specified hash algorithm and key.

Signature

luau
function hmac(algorithm: HashAlgorithm, data: string, key: string): string

Types

luau
type HashAlgorithm = "md5" | "sha1" | "sha256" | "sha512"

Summary

Parameters

ParameterTypeDescription
algorithmHashAlgorithmThe hash algorithm to use.
datastringThe string data to hash.
keystringThe secret key for the HMAC.

Example

lua
local crypto = require("@runtime/crypto")

local mac = crypto.hmac("sha256", "Hello, World!", "my-secret-key")
print(mac) -- 1c3a647...