Hash functions are used to calculate string hash codes, which are unique fixed-length values generated based on input data.
hash.ofCalculates the hash of a string using the specified algorithm.
Signature: hash.of(text string, algo string = “md5”, binary bool = false) string
Arguments:
text — the string to be hashed.algo — the name of the hashing algorithm (default is md5).binary — if true, returns the result as binary data. If false (default), the result will be in hexadecimal encoding.Result: Returns a string with the calculated hash code:
binary is set to false.binary is set to true.Valid algorithm values:
md2, md4, md5, sha1, sha224, sha256, sha384, sha512/224, sha512/256, sha512, sha3–224, sha3–256, sha3–384, sha3–512, ripemd128, ripemd160, ripemd256, ripemd320, whirlpool, tiger128,3, tiger160,3, tiger192,3, tiger128,4, tiger160,4, tiger192,4, snefru, snefru256, gost, gost–crypto, adler32, crc32, crc32b, crc32c, fnv132, fnv1a32, fnv164, fnv1a64, joaat, murmur3a, murmur3c, murmur3f, xxh32, xxh64, xxh3, xxh128, haval128,3, haval160,3, haval192,3, haval224,3, haval256,3, haval128,4, haval160,4, haval192,4, haval224,4, haval256,4, haval128,5, haval160,5, haval192,5, haval224,5, haval256,5.
Note: If the binary parameter is set to true, it is not recommended to use the returned value in messages to avoid crashes.
Example of use:
$hash = hash.of(“A cheeky brown fox cub jumps around a lazy dog.”) // $hash will contain bff8b4bc8b5c1c1d5b3211dfb21d1e76
$hash = hash.of(“A cheeky brown fox cub jumps around a lazy dog.”, “ripemd160”) // $hash will contain 8817ca339f7f902ad3fb456150a1bb9b4cb5dde9
$hash = hash.of(“A cheeky brown fox cub jumps around a lazy dog.”, “sha256”, true) // $hash will contain a binary string (containing non-displayable characters)