std.hash

std.hash provides fast checksums and cryptographic digests for strings.

Reference

md5(s)     # 32-char lowercase hex
sha256(s)  # 64-char lowercase hex
crc32(s)   # 8-char lowercase hex

Each function hashes the string s and returns a lowercase hex digest.

Function Output Notes
md5(s) 32-char hex Cryptographic digest, built in
sha256(s) 64-char hex Cryptographic digest, built in
crc32(s) 8-char hex Fast checksum, not cryptographic

Examples

print(std.hash.md5("hello"))     # 5d41402abc4b2a76b9719d911017c592
print(std.hash.sha256("hello"))  # 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
print(std.hash.crc32("hello"))   # 3610a686

# use with random material
var bytes = std.crypto.random_bytes(16)
print(std.hash.sha256(bytes))

crc32 is intended for quick integrity checks (e.g. file chunks); md5 and
sha256 are the cryptographic options. All three are built-in implementations
that work regardless of OpenSSL availability.

See also