Encryption
Protecting data so only authorized parties can read it.
1The Lock and Key Analogy
Asymmetric: One key locks (public), another unlocks (private). Like a mailbox-anyone can drop mail in, only you have the key to open it.
Encryption transforms readable data (plaintext) into unreadable data (ciphertext). Only those with the correct key can reverse it (decrypt).
2Symmetric Encryption
Same key for encryption and decryption. Fast but key distribution is tricky.
AES-256
Data at rest, database encryption, file encryption
ChaCha20
TLS (mobile), when AES hardware unavailable
Key Challenge
How do you securely share the key? If attacker intercepts the key, encryption is useless.
3Asymmetric Encryption
Public key encrypts, private key decrypts. Solves key distribution.
RSA
Key exchange, digital signatures, certificates
ECDSA
Bitcoin, modern TLS, smaller keys than RSA
Public Key
Share freely. Used to encrypt data or verify signatures.
Private Key
Keep secret! Used to decrypt data or create signatures.
4Hashing (Not Encryption)
Hashing is one-way. You cannot reverse a hash to get the original data. Used for passwords, data integrity, checksums.
bcrypt/scrypt/Argon2
Password hashingIntentionally slow. Salted. Resistant to brute force.
SHA-256
Data integrity, checksumsFast. Not for passwords (too fast to brute force).
MD5/SHA-1
DEPRECATEDBroken. Don't use for security.
5Encryption at Rest vs In Transit
At Rest
Data stored on disk: databases, S3, hard drives
AES-256 encryption. Keys in KMS.
AWS S3 server-side encryption
In Transit
Data moving over network
TLS/HTTPS encrypts the connection
HTTPS, TLS 1.3
End-to-end encryption (E2EE): Data encrypted on sender's device, only decrypted on recipient's device. Server can't read it. (WhatsApp, Signal)
6Common Mistakes
Rolling Your Own Crypto
Don't invent encryption algorithms. Use well-tested libraries (libsodium, OpenSSL).
Hardcoding Keys
Keys in source code = keys in version control = compromised.
Using MD5/SHA-1 for Passwords
Too fast. Use bcrypt, scrypt, or Argon2 which are intentionally slow.
Encrypting with ECB Mode
ECB reveals patterns. Use GCM or CBC with proper IV.
7Key Takeaways
?Quiz
1. Storing user passwords. Best approach?
2. TLS uses which encryption primarily?