crypt.hash Synchronous

Compute a digest of the supplied data using the selected algorithm. Use it to fingerprint file contents or compare whether bytes have changed. A hash does not encrypt data, and a plain digest does not authenticate its sender.

Syntax
Luau
crypt.hash(data: string, algorithm: string, key: string?) -> string

Parameters

Function parameters
ParameterTypeDescription
datastringBytes to hash, up to 16 MiB.
algorithmstringMD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA3-224, SHA3-256, SHA3-384, SHA3-512, or BLAKE2B. Case and common separator variants are normalized.
keystring?Optional raw key for BLAKE2B, up to 64 bytes. Other digest algorithms ignore this argument.

Returns

string

The digest as lowercase hexadecimal text.

Example

Example
Luau
local first = crypt.hash("draft one", "SHA256")
local second = crypt.hash("draft two", "SHA256")
print(first == crypt.hash("draft one", "SHA256")) -- true
print(first == second) -- false
Kawaii documentation