crypt. hash Synchronous
Calculate a digest of bytes so you can compare a file or payload with a known fingerprint. For authentication between two parties, use crypt.hmac instead because an unkeyed digest can be recomputed by anyone.
Luau
crypt.hash(data: string, algorithm: string, key: string?) -> stringParameters
| Parameter | Type | Description |
|---|---|---|
data | string | Bytes to hash, up to 16 MiB. |
algorithm | string | MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA3-224, SHA3-256, SHA3-384, SHA3-512, or BLAKE2B. |
key | string? | Optional raw key for BLAKE2B, up to 64 bytes. Other algorithms ignore it. |
Returns
stringThe digest as lowercase hexadecimal text.
Usage notes
The algorithm name is normalized for case and common separators. The same bytes and algorithm produce the same digest.
Example
Luau
local bytes = "version 2 of my settings"
local fingerprint = crypt.hash(bytes, "SHA-256")
print(fingerprint)
assert(fingerprint == crypt.hash(bytes, "sha256"))