SkillSprout
Chapter 33 · Lesson 2
Intermediate
3 min read

Encryption and HTTPS/TLS

Overview

Encryption scrambles data so only someone with the right key can read it. It protects data while it travels over the network and while it sits on disk.

HTTPS is simply HTTP carried inside an encrypted TLS connection, and it is the reason a coffee-shop Wi-Fi owner cannot read your bank traffic.

Detailed Notes

What is encryption

Encryption turns readable data (plaintext) into unreadable data (ciphertext) using a key. Only a holder of the right key can reverse it.

  • Symmetric encryption: one shared key encrypts and decrypts (AES is the standard). Very fast, good for bulk data. The hard part is sharing the key safely.
  • Asymmetric encryption: a public key encrypts and a matching private key decrypts (or signs). Slower, but solves key sharing: you can publish the public key freely.

The problem it solves

Data on a network crosses many routers and Wi-Fi hops that strangers control, and disks and backups can be stolen. Encryption makes intercepted or stolen data useless without the key (confidentiality).

How it works

In transit: TLS (HTTPS). When your browser connects to a site:

  1. The server sends a certificate: its public key, signed by a trusted certificate authority (CA), proving the server really is who it claims.
  2. The browser checks the certificate. If it is not trusted, you see a warning.
  3. Using asymmetric cryptography, both sides agree on a fresh shared session key.
  4. From then on they use fast symmetric encryption with that session key.

So asymmetric crypto sets up trust and the key; symmetric crypto carries the data. TLS also detects tampering. Use TLS everywhere, including between your own internal services.

At rest. Encrypt databases, disks, object storage and backups, usually with AES. Cloud services offer this as a checkbox.

Key management. Keys are the real secret, so never put them in code or next to the data. A key management service (KMS) stores and rotates master keys. With envelope encryption, each piece of data is encrypted with its own data key, and that data key is encrypted by a master key held in the KMS. Leak one data key and you lose one item, not everything.

Hashing is not encryption. Encryption is reversible with a key. A hash is one-way. Use hashing for passwords and integrity checks, encryption when you must read the data again.

A simple example

You send a letter in a locked box. Asymmetric encryption is like the recipient mailing you an open padlock (public key) that only they can unlock. You use it to lock a note containing a secret key, and from then on you both use that shared key.

System design example

A shopping site serves everything over HTTPS (TLS ends at the load balancer or CDN, and internal calls are also encrypted). The database and backups are encrypted at rest, with data keys protected by a KMS and rotated regularly. Passwords are hashed, not encrypted. The cost is a little CPU and the work of managing keys and certificates, which is small compared with a breach.

Summary

  • Symmetric encryption is fast with one shared key; asymmetric uses a public/private pair and solves key sharing.
  • HTTPS is HTTP over TLS: certificate check, key agreement, then fast symmetric encryption.
  • Encrypt data in transit and at rest; keep keys in a KMS and use envelope encryption.
  • Hashing is one-way (passwords, integrity); encryption is reversible.

Architecture Diagram

Encryption in transit and at rest
Architecture
Browser
Load balancercertificate
App server
Encrypted databaseat rest
KMSmaster key

TLS protects the network path; keys from a KMS protect stored data.

  1. 1The browser verifies the server's certificate and agrees a session key.
  2. 2Requests travel encrypted over HTTPS to the load balancer and onward.
  3. 3The app writes to a database that encrypts data at rest.
  4. 4The data key is protected by a master key in the KMS.

Common Interview Questions

Finished this lesson?

0 of 91 lessons done · 0% of the course