5-min deep dive

Public keys in depth: certificates, certificate authorities and HTTPS

Public-key cryptography solved the problem of “how to hand over the key.” But it creates a new one: “does that public key really belong to that person?” The answer is the digital certificate.

Reading time: about 5 min

← Start with the 1-min version

In the game, this was passing notes in classPlay “Secret Notes in Class”

In the gameIn real IT
You and your friendTwo people exchanging messages
Share set (padlock and stamp sample)Public key
Own set (key and stamp)Private key
Lock with a padlock / open with the keyEncrypt / decrypt
Stamp / check against the sampleSign / verify a signature
Kids in betweenEavesdropper

Quick table: which key for what

Public-key cryptography does two main things: “send a secret” and “prove who you are.” The key point is that the owner of the key you use is reversed between the two.

What you want to doKey to use
Send secret data (encrypt)The receiver’s public key
Read received data (decrypt)The receiver’s private key
SignThe sender’s private key
Verify a signatureThe sender’s public key

If you’re unsure, ask “what can only be done with a private key?” The answer: reading (decrypting) and signing. Both must be things only the owner can do.

Signatures are made on a hash value

A digital signature isn’t made on the document itself, but on its hash value (a fixed-length, fingerprint-like value made from the document), signed with the sender’s private key. The receiver checks the signature with the sender’s public key, takes out the value, and compares it with a hash they compute from the received document.

If they match, two things are confirmed at once: “it was signed with the owner’s private key” and “not a single character of the document was changed.” Hash values are short, so signing is fast too.

Is that public key really theirs?

Anyone can hand out public keys, so a bad actor might hand out their own public key claiming “this is B’s public key.” A digital certificate prevents this.

A digital certificate is a statement — “this public key belongs to this person (this site)” — signed by a trusted third party, a certificate authority (CA). Browsers and operating systems come with the certificates of CAs they trust (root certificates) and use them to check whether a site’s certificate is genuine.

How HTTPS uses it

When you connect to an HTTPS site, the server first sends its digital certificate. The browser checks the CA’s signature and confirms “this really is that site.” Then it safely agrees on a shared key used only for this session, and encrypts the rest of the traffic with fast shared-key encryption.

The division of labor: public-key cryptography for handing over keys and confirming who you’re talking to, shared-key encryption for the bulk of the data.

Field note: watch out for expired certificates

Server certificates have an expiry date. Forget to renew, and browsers show a big warning, so the service looks like it’s down. It’s safest to monitor expiry dates and, if possible, set up automatic renewal (Let's Encrypt and the like).

Also, the golden rule is to lock down permissions on where the private key file sits on the server, and never send it by email or chat. If it leaks, someone can build an impostor site.

Practice questions

Four-choice questions in the style of Japan’s IT Passport and Fundamental Information Technology Engineer exams. Tap below to see the answer.

Q1Which key is used to create a digital signature?

  • AThe sender’s public key
  • BThe sender’s private key
  • CThe receiver’s public key
  • DThe receiver’s private key
Show the answer and explanation

Answer: BOnly the owner must be able to sign, so the signature is made with the sender’s (owner’s) private key. To verify it, you use the sender’s public key.

Q2What does a digital certificate guarantee?

  • AThat the traffic is encrypted
  • BThat a public key is correctly matched to its owner
  • CThat the private key hasn’t leaked
  • DThat the site has no viruses
Show the answer and explanation

Answer: BA digital certificate is a CA-signed guarantee of the match “this public key belongs to this person (this site).”

Q3A wants to send B an email that only B can read and that proves A sent it. Which combination of keys is used to encrypt and to sign?

  • AEncrypt: A’s public key; sign: B’s private key
  • BEncrypt: B’s public key; sign: A’s private key
  • CEncrypt: B’s private key; sign: A’s public key
  • DEncrypt: A’s private key; sign: B’s public key
Show the answer and explanation

Answer: BTo make it readable only by B, encrypt with B’s public key. To prove A sent it, sign with A’s private key.

Summary
  • Encrypt with the receiver’s public key; sign with the sender’s private key
  • Signatures are made on the document’s hash value, which also reveals tampering
  • A digital certificate is a CA’s guarantee that a public key belongs to its owner