Module eco.hash.hmac

HMAC utilities.

This module implements HMAC for the hash modules shipped with eco (currently md5/sha1/sha256).

The returned digest is raw binary bytes. Use eco.encoding.hex.encode if you need a printable hexadecimal string.

Functions

new (hash, key) Create a new HMAC context.
sum (hash, key, data) One-shot HMAC.

Class hmac

hmac:update (data) Update HMAC with more data.
hmac:final () Finalize and return the HMAC digest.


Functions

new (hash, key)
Create a new HMAC context.

Parameters:

Returns:

    hmac HMAC context.

Usage:

    local sha256 = require 'eco.hash.sha256'
    local hmac = require 'eco.hash.hmac'
    local hex = require 'eco.encoding.hex'
    
    local ctx = hmac.new(sha256, 'key')
    ctx:update('12')
    ctx:update('34')
    print(hex.encode(ctx:final()))
sum (hash, key, data)
One-shot HMAC.

Parameters:

Returns:

    string Raw binary digest.

Class hmac

HMAC context returned by hmac.new.
hmac:update (data)
Update HMAC with more data.

Parameters:

hmac:final ()
Finalize and return the HMAC digest.

Returns:

    string Raw binary digest.
generated by LDoc 1.5.0 Last updated 2026-04-09 14:48:22