Import
Hash Functions
createHash()
Creates a Hasher object that can be fed with data repeatedly to generate hash digests.The hashing algorithm to use. One of:
"md4", "md5", "sha1", "sha256", "sha384", "sha512", "sha512_224", "sha512_256", "ripemd160".A Hasher object with
update(data) and digest(encoding) methods.createHMAC()
Creates an HMAC hashing object for generating signed hash digests.The hashing algorithm. One of:
"md4", "md5", "sha1", "sha256", "sha384", "sha512", "sha512_224", "sha512_256", "ripemd160".A shared secret used to sign the data.
A Hasher object with
update(data) and digest(encoding) methods.Direct Hash Functions
md5()
Computes MD5 hash of input data.The input string or ArrayBuffer to hash.
Output encoding:
"base64", "base64url", "base64rawurl", "hex", or "binary".Hash digest as string or array of integers (for binary encoding).
sha256()
Computes SHA-256 hash of input data.The input string or ArrayBuffer to hash.
Output encoding:
"base64", "base64url", "base64rawurl", "hex", or "binary".Hash digest as string or array of integers (for binary encoding).
Other Hash Functions
All hash functions follow the same signature asmd5() and sha256():
md4()
MD4 hashing algorithm
sha1()
SHA-1 hashing algorithm
sha384()
SHA-384 hashing algorithm
sha512()
SHA-512 hashing algorithm
sha512_224()
SHA-512/224 hashing algorithm
sha512_256()
SHA-512/256 hashing algorithm
ripemd160()
RIPEMD-160 hashing algorithm
hmac()
HMAC with any supported algorithm
Random Generation
randomBytes()
Generates cryptographically random bytes.The length of the returned ArrayBuffer.
An ArrayBuffer with cryptographically random bytes.
Use
randomBytes() for cryptographically secure random data. For non-cryptographic randomness, use Math.random().Output Encodings
All hash functions support these output encodings:"hex"- Hexadecimal string (most common)"base64"- Standard base64 encoding"base64url"- URL-safe base64 encoding"base64rawurl"- URL-safe base64 without padding"binary"- Array of integers (0-255)
Use Cases
Request signing
Request signing
Generate HMAC signatures for API authentication:
Password hashing
Password hashing
Hash passwords before sending (though use bcrypt/argon2 in production):
Data integrity
Data integrity
Verify file or data integrity:
Token generation
Token generation
Generate random tokens or IDs: