Class crypto_shash
Lua interface to synchronous message digest (hash) algorithms, including HMAC.
Methods
| crypto_shash:digest (data) | Computes the digest of data in a single call. |
| crypto_shash:digestsize () | Returns the digest size in bytes. |
| crypto_shash:export () | Exports the current internal hash state. |
| crypto_shash:final () | Finalizes and returns the digest. |
| crypto_shash:finup (data) | Feeds final data and returns the digest (update + final in one call). |
| crypto_shash:import (state) | Restores a previously exported hash state. |
| crypto_shash:init () | Initializes the hash state for incremental hashing. |
| crypto_shash:new (algname) | Creates a new SHASH object. |
| crypto_shash:setkey (key) | Sets the key (required for HMAC algorithms). |
| crypto_shash:update (data) | Feeds data into the running hash. |
Methods
- crypto_shash:digest (data)
-
Computes the digest of data in a single call.
Parameters:
- data string
Returns:
-
string
digest bytes
Raises:
on hash failure - crypto_shash:digestsize ()
-
Returns the digest size in bytes.
Returns:
-
integer
- crypto_shash:export ()
-
Exports the current internal hash state.
Returns:
-
string
opaque state blob
- crypto_shash:final ()
-
Finalizes and returns the digest.
Returns:
-
string
digest bytes
Raises:
on hash failure - crypto_shash:finup (data)
-
Feeds final data and returns the digest (update + final in one call).
Parameters:
- data string
Returns:
-
string
digest bytes
Raises:
on hash failure - crypto_shash:import (state)
-
Restores a previously exported hash state.
Parameters:
- state
string
blob returned by
export()
Raises:
on length mismatch - state
string
blob returned by
- crypto_shash:init ()
-
Initializes the hash state for incremental hashing.
Raises:
on initialization failure - crypto_shash:new (algname)
-
Creates a new SHASH object.
Parameters:
- algname string algorithm name (e.g., "sha256", "hmac(sha256)")
Returns:
-
crypto_shash
Raises:
on allocation failureUsage:
local shash = require("crypto").shash local h = shash("sha256")
- crypto_shash:setkey (key)
-
Sets the key (required for HMAC algorithms).
Parameters:
- key string
Raises:
on invalid key or algorithm error - crypto_shash:update (data)
-
Feeds data into the running hash.
Parameters:
- data string
Raises:
on hash failure