Security Basics — SSH, TLS and Certificates›03 · Cryptography without the maths

Lesson 03 of 16 · Why and what

Cryptography without the maths

The four building blocks behind SSH, HTTPS and certificates, explained without maths: symmetric encryption (one shared key, fast), asymmetric keys (a public and a private key), key exchange (agreeing a secret in public) and hashing; and how combining them gives digital signatures. Every later lesson in this course is these four blocks in different arrangements.

Beginner
Key wordscryptographysymmetric encryptionAESasymmetric encryptionpublic keyprivate keykey pairRSAECDSAEd25519key exchangeDiffie-HellmanhashSHA-256digital signaturehybrid encryption

Block 1: symmetric encryption, one shared key

The same key locks and unlocks. Algorithms like AES and ChaCha20 are extremely fast and secure, and they encrypt the actual data in HTTPS, SSH, disk encryption and VPNs.

The catch: both sides need the same key. How do you get a key to a website you have never visited, without anyone on the network seeing it? Blocks 2 and 3 solve that.

Block 2: asymmetric keys, a public and a private half

A key pair is two linked keys:

  • the private key, kept secret by its owner, never sent anywhere;
  • the public key, which can be given to anyone.

What one does, only the other can check or undo. The most important use for this course: the private key signs, and anyone with the public key can verify the signature. That is how a server proves "I am really the owner of this key" in SSH and TLS. Common algorithms: RSA (older, larger keys), ECDSA and Ed25519 (modern, small and fast).

A key pair is like a wax seal and a picture of it. You keep the seal ring (private key) in your pocket. Everyone gets a picture of your seal (public key). When a letter arrives with your seal pressed into the wax, anyone can compare it with the picture and know it came from you, but nobody can make that seal without your ring.

Block 3: key exchange, agreeing a secret in public

Diffie-Hellman (today usually ECDHE, the elliptic-curve, ephemeral version) lets two computers each send a value across a public network and both end up with the same secret, which an eavesdropper who saw both values cannot work out. That shared secret becomes the symmetric key for block 1.

"Ephemeral" means a fresh secret for every connection, thrown away afterwards. That gives forward secrecy: if a server's private key is stolen next year, recorded traffic from today still cannot be decrypted.

Block 4: hashing, a fingerprint

A hash function such as SHA-256 turns any data into a fixed-size fingerprint. Change one bit and the fingerprint changes completely; you cannot work backwards from it.

$ echo -n 'transfer 100' | sha256sum
$ echo -n 'transfer 900' | sha256sum      ← completely different output

Uses: checking a download is not corrupted or tampered with, detecting changed files, and (with special slow hashes) storing passwords.

Putting blocks together: digital signatures

SIGN (owner)                               VERIFY (anyone)
data ──hash──► fingerprint                 data ──hash──► fingerprint ─┐
                    │                                                   ├─ match? ✔ authentic,
          sign with PRIVATE key                                         │          unchanged
                    ▼                       signature ──check with ─────┘
               signature ───── sent with data ──────► PUBLIC key

A signature proves who signed (only the private key could make it) and that the data has not changed since. Certificates (lesson 8), software packages and Git tags all rely on this.

Try it

Sign a message with a new Ed25519 key, verify it, then change one word and verify again.

$ openssl genpkey -algorithm ed25519 -out priv.pem
$ openssl pkey -in priv.pem -pubout -out pub.pem
$ echo "deploy v1.2" > msg.txt
$ openssl pkeyutl -sign -inkey priv.pem -rawin -in msg.txt -out msg.sig
$ openssl pkeyutl -verify -pubin -inkey pub.pem -rawin -in msg.txt -sigfile msg.sig
Signature Verified Successfully
$ echo "deploy v9.9" > msg.txt
$ openssl pkeyutl -verify -pubin -inkey pub.pem -rawin -in msg.txt -sigfile msg.sig
Signature Verification Failure

How SSH and HTTPS use the four blocks

Step Block
Agree a session secret 3. Key exchange (ECDHE)
Server proves its identity 2. Signature with the server's private key
Check the server key is the right one SSH: known_hosts. HTTPS: a certificate signed by a CA
Protect all the data 1. Symmetric encryption (AES-GCM, ChaCha20)
Detect tampering 4. Hash-based message authentication

This mix is called hybrid encryption: slow asymmetric operations once at the start, fast symmetric encryption for everything else.

Recap

  • Symmetric: one shared key, fast, protects the data.
  • Asymmetric: private key signs and stays secret, public key verifies and can be shared.
  • Key exchange: agree a secret in public; ephemeral keys give forward secrecy.
  • Hashing: one-way fingerprint. Signature = hash + private key, verifiable by anyone.

This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.