Best Practices
Cipher selection
Prefer AES-GCM or ChaCha20-Poly1305 for authenticated encryption.
Prefer AES-256-CBC or ChaCha20 (with separate MAC) if AEAD is not available.
Avoid ECB mode entirely; in this library ECB selector is mapped to CTR with zero IV only for compatibility.
Avoid DES/3DES; only use for legacy interoperability with strict key/IV handling.
Asymmetric
Use RSA-OAEP (SHA-256+) to encrypt small payloads such as session keys; do not use it for large data.
Use X25519 or ECDH P-256/P-384 for key exchange; derive symmetric keys via HKDF.
Nonce/IV management
AES-GCM requires a 12-byte nonce. Never reuse a nonce with the same key.
AES CBC/CTR require a 16-byte IV. Never reuse an IV with the same key.
ChaCha20 and ChaCha20-Poly1305 require a 12-byte nonce. Never reuse a nonce with the same key.
DES/3DES CBC/CTR use an 8-byte IV; treat reuse as catastrophic.
Security Best Practices
This guide covers essential security best practices when using cryptographer.js in production applications.
Algorithm Selection
Hash Functions
Password Hashing
Encryption
Key Management
Generate Strong Keys
Key Derivation
Key Storage
Salt Management
Use Unique Salts
Salt Length
Parameter Selection
Argon2 Parameters
PBKDF2 Parameters
bcrypt Parameters
Timing Attacks
Use Timing-Safe Comparison
Constant-Time Operations
Input Validation
Validate Input Parameters
Sanitize Input
Error Handling
Don't Expose Sensitive Information
Handle Errors Gracefully
Memory Management
Clear Sensitive Data
Secure Communication
Authenticated Encryption
Secure Key Exchange
Audit and Monitoring
Log Security Events
Monitor Performance
Compliance and Standards
FIPS Compliance
GDPR Compliance
Testing Security
Test for Common Vulnerabilities
Penetration Testing
Summary
Follow these security best practices:
Use recommended algorithms (SHA-256, Argon2id, AES-256)
Generate strong, random keys and salts
Use timing-safe comparisons to prevent timing attacks
Validate all inputs before processing
Handle errors securely without exposing sensitive information
Clear sensitive data from memory when done
Use authenticated encryption for secure communication
Monitor and log security events
Test for vulnerabilities regularly
Stay compliant with relevant standards
Remember: Security is an ongoing process, not a one-time implementation.
Last updated