Crypto API
Bcrypt password hashing and cryptographic secret key generation.
What It Does
The Crypto API provides secure password/token hashing with bcrypt and cryptographically-strong random key generation using Node.js crypto module.
Key Capabilities
- Bcrypt Hashing: Secure password and token hashing
- Hash Comparison: Verify values against stored hashes
- Secret Key Generation: Cryptographically-random keys for tokens
- Configurable Security: Adjustable salt rounds for performance tuning
Main Components
Encryption Class
class Encryption {
constructor(saltRounds?: number) // default: 10
hash(apiKey: string): Promise<string>
compare(apiKey: string, hash: string): Promise<boolean>
}generateSecretKey Function
generateSecretKey(length?: number): string // default: 48 bytes- Uses
crypto.randomBytes() - Returns hexadecimal string
- Suitable for API keys, tokens, secrets
Usage Pattern
// Generate secret
const secret = generateSecretKey() // Random 48-byte hex
// Hash for storage
const hasher = new Encryption(10)
const hash = await hasher.hash(secret)
// Verify later
const isValid = await hasher.compare(userInput, hash)Common Use Cases
- API key hashing before storage
- Password hashing for authentication
- Token generation and validation
- Secret key creation for sessions
What Customers Don’t Have to Build
- Bcrypt integration
- Salt round configuration
- Cryptographic random generation
- Hash comparison logic
- Async hashing operations
Last updated on