# Common Cryptography Mistakes

> Recognize the real-world crypto failures found in code reviews and pentests: weak randomness, bad modes, hardcoded keys and homemade schemes. Free notes, key...

Canonical: https://www.internhack.in/roadmaps/tracks/cybersecurity/crypto-mistakes
Last updated: 2026-11-28

Recognize the real-world crypto failures found in code reviews and pentests: weak randomness, bad modes, hardcoded keys and homemade schemes.

Intermediate · about 3 hours · difficulty 3/5

Learn first: [Hashing and Password Storage](https://www.internhack.in/roadmaps/tracks/cybersecurity/hashing-passwords)

Strong algorithms rarely break. **Implementations** do. Most crypto findings in audits are about how developers use the primitives.

### The usual suspects

- **Rolling your own crypto**: custom XOR "encryption" or homemade token formats. Always use vetted libraries like libsodium or the platform's high-level APIs.
- **Weak randomness**: using `Math.random()` or Python's `random` for tokens, reset links or keys. Use a CSPRNG such as Python's `secrets` or Node's `crypto.randomBytes`.
- **ECB mode**: encrypts identical blocks to identical output, leaking patterns. Use authenticated modes like GCM.
- **Nonce reuse** with GCM or stream ciphers, which can completely break confidentiality.
- **Hardcoded keys** in source code, mobile apps or container images.
- **Unauthenticated encryption**, allowing attackers to flip bits or run padding-oracle attacks.
- **Disabling certificate checks** in HTTP clients during testing and shipping it.
- **JWT mistakes**: accepting `alg: none`, confusing HS256 and RS256, or using weak signing secrets.

### How to review

Ask: what algorithm, which mode, where does the key come from, where is it stored, how is randomness generated, and is integrity checked? Compare against the OWASP Cryptographic Storage guidance.

### Crypto agility and the future

Post-quantum algorithms (ML-KEM, ML-DSA) are being standardized by NIST and rolled out in TLS. You do not need the math, but know that inventories of where crypto is used make future migrations possible.

Good enough: given a code snippet using encryption or token generation, you can point out at least one of the mistakes above and suggest the fix.

## Key concepts

- **Do not roll your own crypto**
- **CSPRNG vs weak randomness**
- **ECB and nonce reuse**
- **Hardcoded keys**
- **JWT pitfalls**
- **Post-quantum awareness**

## Mini project

Encrypt an image with AES-ECB and AES-GCM in Python, compare the outputs visually, and write a short note explaining the difference to a developer.

## Check yourself

A password reset token is generated with random.randint. What is wrong, and what would you replace it with?

## Free resources

- [OWASP Cryptographic Storage Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html) (OWASP)
- [The Cryptopals Crypto Challenges](https://cryptopals.com/) (Cryptopals)
- [NIST Post-Quantum Cryptography](https://csrc.nist.gov/projects/post-quantum-cryptography) (NIST)

Previous: [PKI and Certificates](https://www.internhack.in/roadmaps/tracks/cybersecurity/pki-certificates) · Next: [Authentication and MFA](https://www.internhack.in/roadmaps/tracks/cybersecurity/authentication-mfa)

## More in Applied Cryptography

- [Symmetric and Asymmetric Encryption](https://www.internhack.in/roadmaps/tracks/cybersecurity/crypto-fundamentals)
- [Hashing and Password Storage](https://www.internhack.in/roadmaps/tracks/cybersecurity/hashing-passwords)
- [PKI and Certificates](https://www.internhack.in/roadmaps/tracks/cybersecurity/pki-certificates)
- [Common Cryptography Mistakes](https://www.internhack.in/roadmaps/tracks/cybersecurity/crypto-mistakes)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Cybersecurity Roadmap](https://www.internhack.in/roadmaps/tracks/cybersecurity)
