Skip to content

Hash Functions

Cryptographic hash functions and HMAC message authentication.

local hash = require("hash")
local hex = hash.md5("data")
local raw = hash.md5("data", true)
ParameterTypeDescription
datastringData to hash
rawboolean?Return raw bytes instead of hex

Returns: string, error

local hex = hash.sha1("data")
local raw = hash.sha1("data", true)
ParameterTypeDescription
datastringData to hash
rawboolean?Return raw bytes instead of hex

Returns: string, error

local hex = hash.sha256("data")
local raw = hash.sha256("data", true)
ParameterTypeDescription
datastringData to hash
rawboolean?Return raw bytes instead of hex

Returns: string, error

local hex = hash.sha512("data")
local raw = hash.sha512("data", true)
ParameterTypeDescription
datastringData to hash
rawboolean?Return raw bytes instead of hex

Returns: string, error

local hex = hash.hmac_md5("message", "secret")
local raw = hash.hmac_md5("message", "secret", true)
ParameterTypeDescription
datastringMessage to authenticate
secretstringSecret key
rawboolean?Return raw bytes instead of hex

Returns: string, error

local hex = hash.hmac_sha1("message", "secret")
local raw = hash.hmac_sha1("message", "secret", true)
ParameterTypeDescription
datastringMessage to authenticate
secretstringSecret key
rawboolean?Return raw bytes instead of hex

Returns: string, error

local hex = hash.hmac_sha256("message", "secret")
local raw = hash.hmac_sha256("message", "secret", true)
ParameterTypeDescription
datastringMessage to authenticate
secretstringSecret key
rawboolean?Return raw bytes instead of hex

Returns: string, error

local hex = hash.hmac_sha512("message", "secret")
local raw = hash.hmac_sha512("message", "secret", true)
ParameterTypeDescription
datastringMessage to authenticate
secretstringSecret key
rawboolean?Return raw bytes instead of hex

Returns: string, error

Fast hash for hash tables and partitioning.

local n = hash.fnv32("data")
ParameterTypeDescription
datastringData to hash

Returns: number, error

Fast hash with larger output for reduced collisions.

local n = hash.fnv64("data")
ParameterTypeDescription
datastringData to hash

Returns: number, error

ConditionKindRetryable
Input not a stringerrors.INVALIDno
Secret not a string (HMAC)errors.INVALIDno

See Error Handling for working with errors.