crypto.hash(algorithm, data)
Create a hash digest of data, using the specified algorithm.
Parameters
algorithm
A string representing the hash algorithm to use :
- "md5" for MD5 hash algorithm
- "sha1" for SHA1 hash algorithm
- "sha256" for SHA256 hash algorithm
- "sha384" for SHA384 hash algorithm
- "sha512" for SHA512 hash algorithm
data
A string or a Buffer that contains the data to hash.
Return value
Returns a Buffer containing the hash value as bytes.Example
local crypto = require "crypto"
local console = require "console"
console.echo = "*"
local sha256 = crypto.hash("sha256", console.readln("Enter the password : "))
-- the lua script don't know the password value, only the hash value
console.write("Password sha256 hash value : ")
console.writecolor("cyan", sha256:encode("hex"), "\n")