SSL/TLS Explained Simply

SSL (Secure Sockets Layer) and TLS (Transport Layer Security) are protocols that secure communication over the internet. TLS is the modern version (SSL is mostly obsolete but people still say "SSL").
🔑 The Goals of SSL/TLS
Encryption → Data is unreadable to attackers.
Authentication → Verify the server (and sometimes client) is genuine.
Integrity → Data isn’t tampered with in transit.
⚙️ How SSL/TLS Works (Simplified Flow)
1. Handshake Initiation
Client (like your browser) says: “Hi server, I want to talk securely. Here are the TLS versions and ciphers I support.”
This is called the ClientHello message.
2. Server Responds
Server replies: “I’ll use this TLS version and cipher. Here’s my certificate proving who I am.”
This is the ServerHello + certificate (which contains the server’s public key, signed by a Certificate Authority).
3. Certificate Validation
The client checks the server’s certificate:
Is it issued by a trusted Certificate Authority (CA)?
Has it expired?
Does the domain match (e.g.,
www.google.com
)?
If valid ✅, continue. If not ❌, you get a warning.
4. Key Exchange
Both sides agree on a session key (a symmetric key).
The method depends on the algorithm:
With RSA: client generates a random key, encrypts it with server’s public key, sends it.
With Diffie-Hellman / ECDHE: both exchange values and independently compute the same session key.
Result: both now share a secret session key.
5. Secure Session Established
All further communication is encrypted with the symmetric session key (fast, efficient).
Messages are also signed with a Message Authentication Code (MAC) to ensure integrity.
🔒 Example
You type
https://bank.com
in your browser.Browser says hello and asks for secure connection.
Bank server sends certificate.
Browser verifies certificate against trusted CA list.
A session key is securely exchanged.
From now on, everything you type (passwords, transactions) is encrypted.
📌 Quick Analogy
Think of SSL/TLS like sending a locked box:
The server certificate is the server’s padlock 🔒 (public key).
The client puts a secret key in the box and locks it with that padlock.
Only the server (with its private key) can open it.
Now both share the secret key → they can lock and unlock messages quickly using it.
🔑 Explain: Symmetric Encryption
Definition:
Symmetric encryption is a cryptographic method where the same key is used for both encryption (locking the message) and decryption (unlocking it).
⚙️ How It Works
Sender (Encrypts):
Takes plaintext (normal data).
Uses a secret key + algorithm (like AES, DES, Blowfish).
Produces ciphertext (scrambled, unreadable data).
Receiver (Decrypts):
Uses the same secret key with the algorithm.
Turns ciphertext back into plaintext.
🔒 Example
Secret Key:
1234
Message:
HELLO
Encryption algorithm scrambles →
X9%T!
Receiver uses the same key (1234) → gets back
HELLO
.
If someone steals the key, they can also decrypt the message → that’s the weakness.
📌 Characteristics
Fast → Much quicker than asymmetric encryption.
Efficient for bulk data (used in TLS after handshake).
Key Distribution Problem → The biggest challenge: how do sender and receiver share the secret key securely without someone intercepting it?
🔑 Common Algorithms
AES (Advanced Encryption Standard) → most widely used today.
DES / 3DES → older, less secure now.
Blowfish / Twofish / ChaCha20 → alternatives.
🎯 Real-World Use
Encrypting data on disk (BitLocker, FileVault).
Protecting communication after TLS handshake (HTTPS traffic).
VPNs, database encryption, Wi-Fi security (WPA2/WPA3).
👉 Analogy:
Think of symmetric encryption like a locked safe.
You and your friend share the same key.
You put a letter inside and lock it.
Your friend unlocks it with the same key.
🔑 Explain: Asymmetric Encryption
Definition:
Asymmetric encryption is a cryptographic method where two different keys are used:
Public Key → used to encrypt data (shared openly).
Private Key → used to decrypt data (kept secret by the owner).
These keys are mathematically related, but you cannot easily figure out the private key from the public one.
⚙️ How It Works
Sender wants to send a secure message:
- Uses the recipient’s public key to encrypt the message.
Receiver gets the message:
Uses their private key to decrypt it.
Only the private key can unlock what the public key encrypted.
🔒 Example
Alice wants to send Bob a secret:
Bob shares his public key openly.
Alice encrypts message
"HELLO"
→ ciphertext (scrambled).Only Bob, with his private key, can decrypt it.
Even if someone intercepts the ciphertext, they can’t decrypt without Bob’s private key.
📌 Characteristics
Secure key sharing → No need to send a secret key ahead of time.
Slower than symmetric encryption (because of heavy math like RSA, ECC).
Often used to exchange keys, then switch to symmetric encryption for speed (like in TLS).
🔑 Common Algorithms
RSA → widely used for encryption & digital signatures.
ECC (Elliptic Curve Cryptography) → faster, stronger security with smaller keys.
DSA / ElGamal → mainly for digital signatures.
🎯 Real-World Use
TLS/SSL handshake (exchanging session keys).
SSH authentication.
Email encryption (PGP, GPG).
Digital signatures (verifying authenticity of software, certificates).
⚖️ Analogy (compared to symmetric encryption)
Symmetric: One shared key, like a house key you both use.
Asymmetric:
Imagine a mailbox:
The public key is the open slot anyone can drop letters into (encrypt).
The private key is the only thing that can open the box and read the letters (decrypt).
✅ That’s why in SSL/TLS:
Asymmetric encryption is used at the start (to exchange the symmetric session key securely).
Symmetric encryption is then used for the actual data transfer (since it’s faster).
🔑 Two Main Uses of Asymmetric Keys
1. Confidentiality (Encryption/Decryption)
Public key → Encrypt
Private key → Decrypt
👉 This ensures only the private key owner can read the message.
✅ Example: Sending a secret to your bank
You encrypt with the bank’s public key.
Only the bank’s private key can decrypt it.
2. Authentication / Digital Signatures
Private key → Sign (encrypt hash)
Public key → Verify (decrypt hash)
👉 This ensures the message really came from the private key owner and wasn’t tampered with.
✅ Example: Software download
Developer signs software with their private key.
Users verify it with the developer’s public key.
⚖️ So:
When the goal is confidentiality → private key is used for decryption.
When the goal is authenticity → private key is used for encryption (signing).
That’s why you’re right — private keys can encrypt too (but usually only for signing, not for hiding data).
🔑 ssh-keygen
Purpose:
A tool specifically for generating, managing, and converting SSH key pairs.
SSH (Secure Shell) uses asymmetric encryption for authentication (not for encrypting all traffic — it switches to symmetric after login, just like TLS).
Common Uses:
Generate an SSH key pair (public/private):
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
-t rsa
→ type (can also beed25519
,ecdsa
).-b 4096
→ key size.-C
→ comment (e.g., email).Creates:
Private key →
~/.ssh/id_rsa
(keep secret).Public key →
~/.ssh/id_
rsa.pub
(shared with server).
Copy public key to server for passwordless login:
ssh-copy-id user@server
Convert keys to different formats:
ssh-keygen -e -f id_rsa.pub > id_rsa_openssh.pub
Where it’s used:
Logging into servers (
ssh user@host
).Git over SSH.
Automating deployments (Ansible, Jenkins).
🔑 openssl
Purpose:
A general-purpose cryptography toolkit.
Works with TLS/SSL, X.509 certificates, hashing, encryption/decryption, and key management.
Much broader than
ssh-keygen
.
Common Uses:
Generate an RSA private key:
openssl genpkey -algorithm RSA -out private.pem -aes256
- Creates
private.pem
(protected with AES).
- Creates
Extract the public key:
openssl rsa -in private.pem -pubout -out public.pem
Create a Certificate Signing Request (CSR) for HTTPS:
openssl req -new -key private.pem -out server.csr
Self-signed certificate (for testing):
openssl req -x509 -new -key private.pem -out cert.pem -days 365
Encrypt/Decrypt data manually:
# Encrypt openssl rsautl -encrypt -inkey public.pem -pubin -in message.txt -out message.enc # Decrypt openssl rsautl -decrypt -inkey private.pem -in message.enc -out message.txt
Where it’s used:
Managing SSL/TLS certificates (HTTPS, mail servers, etc.).
Encrypting files manually.
Checking certificates (
openssl x509 -in cert.pem -text -noout
).
⚖️ Comparison: ssh-keygen
vs openssl
Feature | ssh-keygen 🖥️ | openssl 🌍 |
Scope | SSH authentication only | General cryptography (TLS, certs, files, hashing, etc.) |
Generates | SSH key pairs (id_rsa , id_ed25519 ) | Private/public keys, CSRs, certs |
Key Format | OpenSSH format | PEM, DER, PKCS#8, X.509 |
Used in | SSH, Git over SSH, automation | HTTPS, SSL/TLS, VPNs, PKI infra |
Ease of Use | Simple, focused | Complex, very flexible |
✅ In short:
Use
ssh-keygen
when working with SSH logins or Git repos.Use
openssl
when dealing with certificates, HTTPS, or general encryption.
🔑 Authentication vs Authorization
1. Authentication ✅ (Who are you?)
Definition: The process of verifying someone’s identity.
Goal: Make sure the user is really who they claim to be.
How: By checking credentials (password, fingerprint, OTP, certificate, etc.).
👉 Example:
Logging into Gmail with your email + password.
Swiping a fingerprint to unlock your phone.
SSH key authentication to log into a server.
If authentication fails → you don’t even get into the system.
2. Authorization ✅ (What are you allowed to do?)
Definition: The process of deciding what an authenticated user is allowed to access/do.
Goal: Control permissions and privileges.
How: Using roles, access control lists (ACLs), or policies.
👉 Example:
In Gmail, after logging in:
You can read your emails.
You cannot read someone else’s inbox.
On a Linux server:
A normal user can’t run
systemctl restart sshd
.Only
root
(or sudoers) is authorized.
If authorization fails → you get “Access Denied” or 403 Forbidden.
⚖️ Analogy
Authentication = Showing your ID card to prove who you are.
Authorization = The guard checks if you’re allowed to enter the VIP lounge with that ID.
📌 Quick Comparison Table
Feature | Authentication | Authorization |
Question | Who are you? | What can you do? |
Checks | Identity | Permissions |
Process | Login, password, biometrics, certificates | Roles, policies, ACLs |
Happens | Always first | Only after authentication |
Example | Entering username + password | Deciding if user can access /admin |
👉 In short:
Authentication = identity check.
Authorization = access rights check.
Subscribe to my newsletter
Read articles from Sanket Nankar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
