@eryx/crypto/hmac Module

JSON

HMAC (Hash-based Message Authentication Code).

Computes an authentication tag over data using a secret key and the chosen hash algorithm. The output length equals the digest size of the underlying hash.

local hmac = require("@eryx/crypto/hmac")
local hex  = require("@eryx/encoding/hex")

local key = buffer.fromstring("secret")
local msg = buffer.fromstring("hello")
print(hex.encode(hmac.sha256(key, msg)))

Summary

Functions

hmac.md5(key: buffer, data: buffer)buffer
hmac.sha1(key: buffer, data: buffer)buffer
hmac.sha224(key: buffer, data: buffer)buffer
hmac.sha256(key: buffer, data: buffer)buffer
hmac.sha384(key: buffer, data: buffer)buffer
hmac.sha512(key: buffer, data: buffer)buffer
hmac.sha3_224(key: buffer, data: buffer)buffer
hmac.sha3_256(key: buffer, data: buffer)buffer
hmac.sha3_384(key: buffer, data: buffer)buffer
hmac.sha3_512(key: buffer, data: buffer)buffer

API Reference

Functions

hmac.md5

Computes HMAC-MD5 over data with key.

hmac.md5(key: buffer, data: buffer)buffer

Parameters

key: buffer

Secret key (any length).

data: buffer

Input data.

Returns

buffer

16-byte MAC.

hmac.sha1

Computes HMAC-SHA1 over data with key.

hmac.sha1(key: buffer, data: buffer)buffer

Parameters

key: buffer

Secret key (any length).

data: buffer

Input data.

Returns

buffer

20-byte MAC.

hmac.sha224

Computes HMAC-SHA224 over data with key.

hmac.sha224(key: buffer, data: buffer)buffer

Parameters

key: buffer

Secret key (any length).

data: buffer

Input data.

Returns

buffer

28-byte MAC.

hmac.sha256

Computes HMAC-SHA256 over data with key.

The most common HMAC variant. Suitable for API authentication, signed cookies, and TOTP/HOTP tokens.

hmac.sha256(key: buffer, data: buffer)buffer

Parameters

key: buffer

Secret key (any length).

data: buffer

Input data.

Returns

buffer

32-byte MAC.

hmac.sha384

Computes HMAC-SHA384 over data with key.

hmac.sha384(key: buffer, data: buffer)buffer

Parameters

key: buffer

Secret key (any length).

data: buffer

Input data.

Returns

buffer

48-byte MAC.

hmac.sha512

Computes HMAC-SHA512 over data with key.

hmac.sha512(key: buffer, data: buffer)buffer

Parameters

key: buffer

Secret key (any length).

data: buffer

Input data.

Returns

buffer

64-byte MAC.

hmac.sha3_224

Computes HMAC-SHA3-224 over data with key.

hmac.sha3_224(key: buffer, data: buffer)buffer

Parameters

key: buffer

Secret key (any length).

data: buffer

Input data.

Returns

buffer

28-byte MAC.

hmac.sha3_256

Computes HMAC-SHA3-256 over data with key.

hmac.sha3_256(key: buffer, data: buffer)buffer

Parameters

key: buffer

Secret key (any length).

data: buffer

Input data.

Returns

buffer

32-byte MAC.

hmac.sha3_384

Computes HMAC-SHA3-384 over data with key.

hmac.sha3_384(key: buffer, data: buffer)buffer

Parameters

key: buffer

Secret key (any length).

data: buffer

Input data.

Returns

buffer

48-byte MAC.

hmac.sha3_512

Computes HMAC-SHA3-512 over data with key.

hmac.sha3_512(key: buffer, data: buffer)buffer

Parameters

key: buffer

Secret key (any length).

data: buffer

Input data.

Returns

buffer

64-byte MAC.