Hash Functions
cryptographer.js provides a comprehensive set of hash functions, from legacy algorithms to modern, high-performance options.
Overview
Hash functions take arbitrary data and produce a fixed-size output (digest). They are used for:
Data integrity verification
Digital signatures
Password hashing (with KDF functions)
Checksums
Deduplication
Supported Algorithms
SHA-256
256 bits
FIPS 180-4
✅ Recommended
General purpose, digital signatures
SHA-512
512 bits
FIPS 180-4
✅ Recommended
Higher security, digital signatures
SHA3-256
256 bits
FIPS 202
✅ Recommended
Latest standard, future-proof
SHA3-512
512 bits
FIPS 202
✅ Recommended
Latest standard, higher security
BLAKE2b
512 bits
RFC 7693
✅ Recommended
Fast, secure, general purpose
BLAKE2s
256 bits
RFC 7693
✅ Recommended
Optimized for 8-32 bit platforms
BLAKE3
256 bits
-
✅ Recommended
Extremely fast, secure
SHA-1
160 bits
RFC 3174
⚠️ Legacy only
Legacy compatibility
MD5
128 bits
RFC 1321
⚠️ Legacy only
Legacy compatibility
MD4
128 bits
RFC 1320
⚠️ Legacy only
Legacy compatibility
Whirlpool
512 bits
ISO/IEC 10118-3
✅ Supported
512-bit hash function
RIPEMD-160
160 bits
-
✅ Supported
Bitcoin, cryptocurrencies
Basic Usage
Simple Hash
Output Formats
Input Types
Streaming API
For large files or data streams, use the streaming API:
Streaming with Files
Algorithm-Specific Functions
SHA Family
BLAKE Family
Legacy Algorithms
Specialized Algorithms
Performance Comparison
Sample performance (Linux x64 / Node 20; higher = better):
Note: crypto-js does not implement BLAKE2b/BLAKE2s/BLAKE3. Mark these "vs crypto-js" as N/A.
BLAKE3
0.010 M
N/A
General purpose, speed critical
BLAKE2b
0.66 M
N/A
General purpose, high security
BLAKE2s
0.65 M
N/A
Optimized for small platforms
SHA-256
0.54 M
3.3× faster
Digital signatures, compatibility
SHA-512
0.59 M
16× faster
Higher security requirements
SHA3-256
0.55 M
33.5× faster
Latest standard, future-proof
Security Considerations
Algorithm Selection
Salt and Pepper
For password hashing, use KDF functions instead:
Length Extension Attacks
Some hash functions are vulnerable to length extension attacks:
Error Handling
TypeScript Support
API Reference
Function Signature
Types
Available Functions
crypto.sha.sha1(input, options?)crypto.sha.sha256(input, options?)crypto.sha.sha512(input, options?)crypto.sha.sha3_256(input, options?)crypto.sha.sha3_512(input, options?)crypto.sha.md4(input, options?)crypto.sha.md5(input, options?)crypto.sha.blake2b(input, options?)crypto.sha.blake2s(input, options?)crypto.sha.blake3(input, options?)crypto.sha.whirlpool(input, options?)crypto.sha.ripemd160(input, options?)
Streaming API
Last updated