Skip to content
Encoding & cryptographyReference

crypt.hash

Calculate a hexadecimal digest of local bytes.

Details#

Calculate a hexadecimal digest of local bytes. Lowercase hexadecimal digest. An unsupported algorithm or hashing failure raises an error.

Signature#

Luau
crypt.hash(data: string, algorithm: string?): string

Parameters#

ParameterTypeDescription
datastringRaw bytes to hash.
algorithmoptionalstringDefault sha384. Accepts md5, sha1, sha224, sha256, sha384, sha512 and sha3-224/256/384/512; SHA-3 also accepts an underscore instead of the hyphen. Names are case-insensitive.

Returns#

Lowercase hexadecimal digest. An unsupported algorithm or hashing failure raises an error.

Examples#

Local example

Luau
print(crypt.hash("hello", "sha256"))
-- 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824