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:
- hash table Hash module (must be one of the eco hash modules (e.g. eco.hash.sha256)).
- key string Secret key.
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:
- hash table Hash module (must be one of the eco hash modules (e.g. eco.hash.sha256)).
- key string Secret key.
- data string Data to authenticate.
Returns:
-
string
Raw binary digest.
Class hmac
HMAC context returned by hmac.new.