Syntax
crypt.hash(data: string, algorithm?: "sha256" | "sha1" | "sha224" | "sha384" | "sha512" | "md5" | "sha3-224" | "sha3-256" | "sha3-384" | "sha3-512"): stringArguments
| Name | Type | Description |
|---|---|---|
data | string | Input byte string or text processed by the function. |
algorithm? | "sha256" | "sha1" | "sha224" | "sha384" | "sha512" | "md5" | "sha3-224" | "sha3-256" | "sha3-384" | "sha3-512" | Hash algorithm. Defaults to sha256. |
Returns
| Name | Type | Description |
|---|---|---|
digest | string | Lowercase hexadecimal hash digest. |
Description
Hashes a string with the selected algorithm and returns the digest.
Call it with 2 parameter(s): data, algorithm. The argument table explains which values are required and which ones only refine the behavior.
It returns digest (string). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Create a SHA-256 digest for a string.
local digest = crypt.hash("hello world", "sha256")
print(digest)