crypt.hash

Generates a hash of the provided data.

Syntax

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

Parameters

ParameterTypeDescription
datastringThe data to hash
algorithmstringRequired hash algorithm name
keystring?Optional key for BLAKE2B; ignored by other algorithms

Returns

TypeDescription
stringThe hexadecimal hash string

Description

crypt.hash generates a cryptographic hash of the input data using the specified algorithm.

Supported Algorithms

  • MD5
  • SHA1
  • SHA224
  • SHA256
  • SHA384
  • SHA512
  • SHA3-224
  • SHA3-256
  • SHA3-384
  • SHA3-512
  • BLAKE2B

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)