Ravindra BagaleCourses & study guides

33. Cryptography Basics

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

Crypto madhe sarvat jast breaches algorithm tutlya mule nahi, tar key management chya chukamule hotat – key code madhe, key email madhe, key kadhich rotate nahi. Algorithm AES asla tari key sambhalli nahi tar sagla vyartha.

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