Practice library / Security fundamentals
Workbook · Easy · 3 hours
Cryptography Fundamentals
Symmetric, asymmetric, hashing, PKI, TLS, and common crypto weaknesses.
On this page 8 sections
Cryptography is the maths behind every HTTPS connection, every password store, and every signed binary that you trust. This workbook covers the ideas that a security engineer must hold in their head: symmetric and asymmetric encryption, hash functions, PKI and X.509, TLS, and the common weaknesses that real attackers exploit. It names the modern primitives (AES-GCM, Argon2, Ed25519) and the broken ones (RC4, MD5, SHA-1) so that you can read a config file and judge it. The goal is not to invent crypto, but to recognise weak keys, padding oracles, hash collisions, and certificate games the moment you see them in a scan or a report.
Chapter 1 — Why Cryptography Matters
Cryptography is the mathematical foundation of all security. Every HTTPS connection, every password database, every signed code package depends on it. Security professionals who do not understand cryptography miss entire attack classes: weak keys, padding oracles, hash collisions, and certificate spoofing.
Chapter 2 — Symmetric Encryption
The same key encrypts and decrypts. Symmetric encryption is fast and suitable for bulk data. The modern standard is AES-256-GCM. The hard problem is key exchange.
| Algorithm | Key Size | Status |
|---|---|---|
| AES-256-GCM | 256 bit | Recommended |
| ChaCha20-Poly1305 | 256 bit | Recommended |
| AES-128-CBC | 128 bit | Padding oracle risk without MAC |
| 3DES | 112 bit | Deprecated (SWEET32 attack) |
| RC4 | variable | Broken — never use |
Chapter 3 — Asymmetric Encryption
Asymmetric encryption uses two keys: a public key (to encrypt or verify) and a private key (to decrypt or sign). It solves the key exchange problem. Common algorithms are RSA, ECDSA, and Ed25519. They are used in TLS handshakes, SSH, code signing, and PGP.
# Generate RSA key pair
openssl genrsa -out private.pem 4096
openssl rsa -in private.pem -pubout -out public.pem
# Encrypt with public key
openssl rsautl -encrypt -pubin -inkey public.pem -in plaintext.txt -out encrypted.binChapter 4 — Hashing & Integrity
Hash functions are one-way functions. The same input always produces the same output, and the output is infeasible to reverse. Hashes are used for password storage, file integrity, and digital signatures.
| Hash | Output | Security |
|---|---|---|
| SHA-256 | 256 bit | Secure |
| SHA-3 | 256-512 bit | Secure |
| bcrypt | 60 chars | Password storage — use this |
| SHA-1 | 160 bit | Collision found — avoid |
| MD5 | 128 bit | Collision trivial — broken |
Chapter 5 — PKI & Digital Certificates
PKI (Public Key Infrastructure) is the trust system behind HTTPS. X.509 certificates bind a public key to an identity, signed by a Certificate Authority (CA). Certificate transparency logs (crt.sh) are a rich OSINT source. They list the certificates issued for a domain, including subdomains that were previously unknown.
# View certificate details
openssl s_client -connect target.com:443 | openssl x509 -noout -text
# Find subdomains via certificate transparency
curl "https://crt.sh/?q=%.target.com&output=json" | python3 -c "import sys,json; [print(r['name_value']) for r in json.load(sys.stdin)]"Chapter 6 — TLS/SSL Deep Dive
# Test TLS configuration
testssl.sh https://target.com
sslscan target.com
# Check for weak protocols and cipher suites
nmap --script ssl-enum-ciphers -p 443 target.comChapter 7 — Common Crypto Weaknesses
| Weakness | Attack |
|---|---|
| CBC mode without MAC | Padding Oracle (POODLE, BEAST) |
| ECB mode | Pattern leakage — identical blocks produce identical ciphertext |
| Weak random number generator | Predictable nonces leading to key recovery |
| Short keys under 128 bit | Brute force feasible |
| MD5/SHA1 for signatures | Collision attacks |
| Reused nonces in stream ciphers | XOR ciphertexts together to recover plaintext |
Chapter 8 — Crypto in Practice
Never roll your own cryptography. Use well-tested libraries: libsodium, cryptography.io (Python), BouncyCastle (Java). For passwords: bcrypt, scrypt, or Argon2 — never plain SHA-256. For symmetric encryption: AES-256-GCM or ChaCha20-Poly1305. For TLS: minimum TLS 1.2, prefer TLS 1.3, enforce HSTS.
Workbook complete. You have covered all chapters. Mark it complete below and choose your next item in the practice library.
Sign in to track progress and send feedback.
Related
This workbook is extra practice for the course Security fundamentals. Do the lessons first.Open the course