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.

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.
keystring?Optional raw key for BLAKE2B, up to 64 bytes. Other algorithms ignore it.

Returns

string

The 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

Example
Luau
local bytes = "version 2 of my settings"
local fingerprint = crypt.hash(bytes, "SHA-256")
print(fingerprint)
assert(fingerprint == crypt.hash(bytes, "sha256"))
Kawaii documentation