crypt.hash
Generates a hash of the provided data.
Syntax
crypt.hash(data: string, algorithm: string, key?: string) -> stringParameters
| Parameter | Type | Description |
|---|---|---|
data | string | The data to hash |
algorithm | string | Required hash algorithm name |
key | string? | Optional key for BLAKE2B; ignored by other algorithms |
Returns
| Type | Description |
|---|---|
string | The hexadecimal hash string |
Description
crypt.hash generates a cryptographic hash of the input data using the specified algorithm.
Supported Algorithms
MD5SHA1SHA224SHA256SHA384SHA512SHA3-224SHA3-256SHA3-384SHA3-512BLAKE2B
Example
local data = "Hello, World!"
local hash = crypt.hash(data, "SHA256")
print("SHA256:", hash)
-- Other algorithms
print("MD5:", crypt.hash(data, "MD5"))
print("SHA1:", crypt.hash(data, "SHA1"))
print("SHA512:", crypt.hash(data, "SHA512"))Use Cases
- Verifying data integrity
- Creating unique identifiers
- Content fingerprints and integrity checks (not password storage)
Related Functions
crypt.hmac- HMAC authentication