33.6 Common Crypto Mistakes and Attacks
| Mistake | Why it is dangerous | Fix |
|---|---|---|
| Storing passwords with MD5/SHA-1 or no salt | Cracked quickly with Hashcat and rainbow tables | bcrypt/Argon2 via password_hash() |
| Hard-coded keys in source code | Anyone with the code has the key | KMS, Secrets Manager, environment variables |
| Using ECB mode or old ciphers (DES, RC4) | Patterns leak, known breaks | AES-GCM or ChaCha20-Poly1305 |
| Rolling your own crypto | Subtle bugs you cannot see | Use well-known libraries (OpenSSL, libsodium) |
| Old TLS versions, expired certificates | Downgrade and MITM attacks | TLS 1.2/1.3 only, auto-renew certificates |
| Weak random numbers | Predictable tokens and keys | Use a cryptographic random generator (random_bytes() in PHP) |
| Treating encoding as encryption | Anyone can decode | Encrypt properly |
Common attack names you should recognise: brute force (try every key), dictionary/rainbow table (pre-computed hashes), man-in-the-middle (intercept and relay), downgrade (force weaker protocol), side-channel (leak through timing or power), and "harvest now, decrypt later" – the reason organisations are planning moves to post-quantum cryptography, which NIST began standardising in 2024.
Ravindra Bagale's Tip
Most crypto breaches happen not because an algorithm was broken, but because of key management mistakes – the key in the code, the key in an email, the key never rotated. Even with AES, if the key isn't looked after, everything is wasted.
Ravindra Bagale's Tip – मराठी
Crypto मध्ये सर्वात जास्त breaches algorithm तुटल्यामुळे नाही, तर key management च्या चुकांमुळे होतात – key code मध्ये, key email मध्ये, key कधीच rotate नाही. Algorithm AES असला तरी key सांभाळली नाही तर सगळे व्यर्थ.
Ravindra Bagale's Tip – हिंदी
Crypto में ज़्यादातर breaches algorithm टूटने से नहीं, बल्कि key management की गलतियों से होते हैं – key code में, key email में, key कभी rotate नहीं. Algorithm AES हो फिर भी key नहीं संभाली तो सब बेकार.
Practice task
Review the PHP code of your reels app (Chapter 16) and find: how passwords are stored, where the DB password lives, how session tokens are generated and which TLS versions your server allows. Write one fix for each weakness you find, using the table above.
Crypto quick reference
| Need | Use |
|---|---|
| Check a file did not change | SHA-256 (sha256sum) |
| Store user passwords | bcrypt / Argon2 (password_hash()) |
| Encrypt data at rest | AES-256-GCM, keys in KMS |
| Share a secret with someone new | Their public key (RSA/ECC) or ECDHE key exchange |
| Prove who sent it | Digital signature with a private key |
| Secure a website | TLS 1.2/1.3 with a CA-signed certificate |