Skip to content

@crypto

Import this module with import @crypto.

Function Signature Description
sha256 (data string) -> string SHA-256 hash (hex)
sha1 (data string) -> string SHA-1 hash (hex). Broken for collision resistance; ships for HMAC-SHA1 / TOTP
sha512 (data string) -> string SHA-512 hash (hex)
md5 (data string) -> string MD5 hash (hex)
hmac_sha256 (key string, data string) -> string RFC 2104 HMAC-SHA-256 (hex)
hmac_sha1 (key string, data string) -> string RFC 2104 HMAC-SHA-1 (hex)
constant_time_equal (a string, b string) -> bool Compare without an early return on mismatch; a length difference is folded into the result
crc32 (data string) -> u64 IEEE CRC-32 checksum (polynomial 0xEDB88320). A checksum, not a cryptographic hash
entropy (data string) -> f64 Shannon entropy of data in bits per byte (0.0–8.0); "" returns 0.0
totp (secret string, timestamp i64, digits i64) -> string RFC 6238 TOTP over the raw secret bytes (SHA-1, 30 s step), zero-padded to digits; panics (P0126) if digits is outside 1–9
random_hex (length i64) -> string Cryptographically secure random hex string