Foundations: web, servers, containersLesson 4 of 13
Cryptography a Developer Needs
You rarely write crypto code, but you configure it every day: TLS, JWTs, SSH keys, signed images, secrets in a KMS. Follow one message from a sender to a receiver and see which tool guards which property, and how each one breaks when misused.
Tool—
Guarantees—
Key—
You meet it in—
RequestResponse / reportWatchAppears in a later step
What you will learn
- A hash checks integrity but anyone can recompute it
- HMAC and AES-GCM: one shared key for integrity and secrecy
- ECB mode, nonce reuse, MD5 and SHA-1
- Signatures: sign with the private key, verify with the public key
- Why passwords are hashed slowly, never encrypted
Which tool answers which question
| Tool | Integrity | Secrecy | Who sent it | Key | Where you see it |
|---|---|---|---|---|---|
| Hash (SHA-256) | Yes, if the digest is trusted | No | No | None | Image digests, file checksums |
| HMAC | Yes | No | Someone holding the shared key | One shared secret | Webhook signatures, JWT HS256, API request signing |
| AEAD (AES-GCM, ChaCha20-Poly1305) | Yes | Yes | Someone holding the shared key | One shared secret | TLS records, disk and database encryption, KMS data keys |
| Signature (Ed25519, ECDSA, RSA) | Yes | No | The private key holder, checkable by anyone | Private signs, public verifies | JWT RS256/ES256, cosign, SSH, certificates |
| Key exchange (ECDHE) | — | Makes a shared key | Only with a signature on top | Throwaway key pairs | TLS 1.3, SSH |
| Password hash (Argon2id, scrypt, bcrypt) | Checks a guess | — | — | Per-user salt, cost settings | User login databases |
| Mistake | What goes wrong | Do instead |
|---|---|---|
| Homemade scheme or protocol | Subtle flaws that tests never catch | Use a vetted library's high-level API, and TLS for transport |
| ECB mode | Equal blocks give equal ciphertext, patterns leak | Use an AEAD mode (GCM) |
| Reusing a GCM nonce | Plaintext XOR leaks, tags can be forged | Random 96-bit nonce or counter per message, rotate keys |
| MD5 or SHA-1 for security | Collisions let an attacker swap content | SHA-256 or better |
| Encrypting or fast-hashing passwords | A key leak or a GPU recovers them | Argon2id, scrypt or bcrypt with a salt |
== to compare MACs | Timing leaks how many bytes matched | Constant-time compare |
Try it yourself
echo -n 'hello' | openssl dgst -sha256 # Hash: same input, same digest
echo -n 'hello!' | openssl dgst -sha256 # One character changes everything
echo -n 'payload' | openssl dgst -sha256 -hmac 'secret' # HMAC with a shared key
openssl genpkey -algorithm ed25519 -out key.pem # Private key
openssl pkey -in key.pem -pubout -out pub.pem # Public key derived from it
echo 'release v1' > msg.txt
openssl pkeyutl -sign -inkey key.pem -rawin -in msg.txt -out msg.sig # Sign with private
openssl pkeyutl -verify -pubin -inkey pub.pem -rawin -in msg.txt -sigfile msg.sig # Verify with public
openssl s_client -connect example.com:443 -tls1_3 </dev/null 2>/dev/null | grep -iE 'cipher|temp key|group' # AEAD cipher and key exchange group (X25519, or hybrid X25519MLKEM768)
ssh-keygen -t ed25519 -f ./demo_key -N '' && ssh-keygen -lf ./demo_key.pub # SSH key pair and its SHA256 fingerprint
htpasswd -nbBC 12 alice 'correct horse' # bcrypt hash, cost 12 ($2y$12$...)
Check yourself
Further reading: OWASP Cryptographic Storage Cheat Sheet · OWASP Password Storage Cheat Sheet · RFC 8446: TLS 1.3 · Encrypting Secret Data at Rest (Kubernetes) · HTTPS and Certificates · How Logging In Works (Sessions, JWT, OIDC)