crypto

native module

Hash digests + a CSPRNG. import "crypto". Digests return lowercase hex. Broader crypto (AEAD, signatures, KDFs) is intentionally left to an extension.

crypto.sha256(s: string) => string

SHA-256 hex digest.

crypto.sha512(s: string) => string

SHA-512 hex digest.

crypto.sha1(s: string) => string

SHA-1 hex (LEGACY/insecure; interop only).

crypto.md5(s: string) => string

MD5 hex (LEGACY/insecure; interop only).

crypto.hmac_sha256(key, msg: string) => string

HMAC-SHA256 tag as hex.

crypto.secure_random(n: int) => string

n cryptographically-secure random bytes.

crypto.constant_time_eq(a, b: string) => bool

Compare two strings (e.g. hex digests/MACs) in constant time, without leaking where they first differ.

On this page