Skip to content
Module 01

PKI Foundations

Keys, certificates, certificate authorities, chains of trust and revocation — the ideas everything else builds on.

PKIBeginner 25 min

Public Key Infrastructure (PKI) is the set of people, policies and software that lets two strangers on a network decide whether to trust each other. Every padlock in your browser, every signed software update and every enterprise Wi-Fi login leans on it.

A hash function turns any amount of data into a short, fixed-size fingerprint. SHA-256 always gives 256 bits, written as 64 hex characters. Two things make it useful:

  • The same input always gives the same hash.
  • You can’t work backwards from a hash, and you can’t find two inputs with the same hash.

Change one character and the hash changes completely. Signatures and certificate fingerprints are built on this.

It starts with a key pair: a private key you keep secret and a public key you can hand to anyone. Data signed with the private key can be verified with the public key. Nobody can forge that signature without the private key.

Strictly, you don’t sign the data. You sign its hash. That’s why signing a 4 GB file is as fast as signing a tweet.

The three key types you’ll meet:

Type Notes
RSA The oldest and most widely supported. Keys are large: 2048 bits or more.
ECDSA (P-256) Elliptic-curve keys. Much smaller and faster for the same strength. step uses it by default.
Ed25519 A newer elliptic-curve scheme. Common in SSH. X.509 support is still uneven.

You need the step CLI and OpenSSL from Lab Setup. Make a folder:

terminal
mkdir -p ~/pki-lab/foundations && cd ~/pki-lab/foundations

Write a message and hash it:

terminal
echo "Meet at the usual place at 9." > message.txt
terminal
shasum -a 256 message.txt
Expected output
7b9f06f5a39eae74b95b06181dbfbf9f1210fb3f756a45c38c54bc5af9bee9bb message.txt

Your hash is the same as this one, because your input is the same.

Make a key pair. Choose a password to protect the private key:

terminal
step crypto keypair alice.pub alice.key
Expected output
Your public key has been saved in alice.pub.
Your private key has been saved in alice.key.

Look at the public key. It’s safe to share:

terminal
cat alice.pub
Expected output
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEfNJAO7q8L0Gn9Pv87tU62DN8pDu+
vtHs7ppwqz9SkpPPlpH2AqyZqSS11Yf/6Oxg36joeIlafEXV4xDfcYwXsw==
-----END PUBLIC KEY-----

Yours is different. This text format is PEM: base64 data between BEGIN and END lines.

Sign the message with the private key. Enter the key password when OpenSSL asks:

terminal
openssl dgst -sha256 -sign alice.key -out message.sig message.txt

Verify it with the public key:

terminal
openssl dgst -sha256 -verify alice.pub -signature message.sig message.txt
Expected output
Verified OK

Anyone with alice.pub can run that check. Only the holder of alice.key could have made the signature.

Change the 9 to an 8:

terminal
echo "Meet at the usual place at 8." > message.txt
terminal
shasum -a 256 message.txt
Expected output
be19a7ebd3b7dae617543e334c5f81d2050d6cad85ea117a167f1e9fd7992855 message.txt

One character changed, and the whole hash changed. Verify the old signature against the new message:

terminal
openssl dgst -sha256 -verify alice.pub -signature message.sig message.txt
Expected output
Verification failure

The signature still belongs to Alice. It just doesn’t match this message any more. That’s how a browser knows a certificate hasn’t been edited since the CA signed it.

A public key on its own says nothing about who owns it. A certificate binds a public key to an identity — a hostname, a person, a device — and is signed by someone you already trust. The common format is X.509.

  • Subject — who the certificate is for.
  • Subject Alternative Name (SAN) — the names it is actually valid for, like api.example.com.
  • Issuer — the authority that signed it.
  • Validity — not-before and not-after dates.
  • Key Usage / Extended Key Usage — what it may be used for, such as server auth or client auth.

A Certificate Authority (CA) signs certificates. Usually a long-lived root CA, kept offline, signs an intermediate CA. The intermediate signs everyday leaf certificates. A verifier walks the chain from the leaf up until it reaches a root it already trusts.

Root CAoffline, self-signedIntermediate CAsigns dailyLeaf certificateapi.example.comsignssigns

Where do roots come from? Your operating system and browser ship with a trust store of more than 100 public roots. A private PKI, like the one you’ll build, adds its own root to the machines that should trust it, and to nothing else.

Certificates expire on purpose — short lifetimes limit the damage of a stolen key. When a key is compromised before then, the CA can revoke the certificate. It publishes that through a CRL (a list) or OCSP (a live lookup).

Check yourself

Tap a card to flip it. Nothing is scored or saved.

Progress is saved in this browser only.