Cryptographic Failure

Cryptographic Failure

One-liner: Sensitive data exposed due to weak/missing encryption, poor key management, or using broken algorithms.

🎯 What Is It?

This is A04 of OWASP. Cryptographic failures occur when sensitive data isn't properly protectedβ€”either not encrypted, using weak algorithms, or with poor key management.

πŸ’₯ Why It Matters (Impact)

πŸ“Š Common Failure Patterns

Failure Risk Fix
No encryption at rest Database dump = full breach AES-256-GCM
No encryption in transit MITM attacks TLS 1.3
Weak hashing (MD5, SHA1) Password cracking bcrypt, Argon2
Hardcoded secrets Secrets in Git history Vault, KMS
Weak algorithms (DES, RC4) Cryptanalysis attacks AES, ChaCha20
Poor key management Keys never rotated Key Management Lifecycle (KML)
Rolling own crypto Guaranteed vulnerabilities Use proven libraries

πŸ”¬ Vulnerable vs Secure Examples

# ❌ VULNERABLE: MD5 for passwords
import hashlib
hashed = hashlib.md5(password.encode()).hexdigest()  # Crackable in seconds!

# βœ… SECURE: bcrypt with salt
import bcrypt
hashed = bcrypt.hashpw(password.encode(), bcrypt.gensalt(rounds=12))
# ❌ VULNERABLE: Hardcoded API key
API_KEY = "sk-1234567890abcdef"  # In source code!

# βœ… SECURE: Environment variable or secrets manager
import os
API_KEY = os.environ.get('API_KEY')  # Or use HashiCorp Vault, AWS Secrets Manager

πŸ” Encryption Standards (2025)

Use Case Recommended Avoid
Symmetric encryption AES-256-GCM, ChaCha20-Poly1305 DES, 3DES, RC4, ECB mode
Password hashing Argon2id, bcrypt, scrypt MD5, SHA1, SHA256 (plain)
TLS TLS 1.3, TLS 1.2 (strong ciphers) SSL, TLS 1.0, TLS 1.1
Key exchange ECDH (Curve25519), RSA-2048+ RSA-1024, DH-1024
Signing Ed25519, ECDSA, RSA-PSS RSA-PKCS1v1.5, DSA

πŸ›‘οΈ Prevention Checklist

Control Implementation
Classify data Know what's sensitive, encrypt appropriately
Encrypt at rest Database, backups, logs
Encrypt in transit TLS everywhere, HSTS
Strong algorithms Follow NIST/OWASP recommendations
Key management Hashicorp Vault, AWS KMS, Azure Key Vault
Regular rotation Key Rotation, Cryptoperiod
No hardcoded secrets Environment vars, secrets managers

🎀 Interview STAR Example

Situation: Security audit found passwords stored as unsalted MD5 hashes in production database.
Task: Migrate to secure password storage without disrupting 50,000 users.
Action: Implemented bcrypt with cost factor 12. Created migration that re-hashed passwords on next login. Forced password reset for inactive accounts after 90 days. Added password breach checking against HaveIBeenPwned.
Result: 100% migration to bcrypt within 60 days. No user-facing incidents during transition.

πŸ“š References