DML School of Technology
Menu

Open to everyone Reading, lesson 48 of 100, 2 min read

Public keys and digital signatures

Two keys that belong together

In asymmetric (public-key) cryptography, each person or server has a key pair:

  • a public key, shared openly with anyone;
  • a private key, kept secret and never shared.

What one key does, only the other can undo.

Encryption with key pairs

To send Ada a secret, you encrypt it with Ada's public key. Only Ada's private key can decrypt it. You never needed a shared secret.

Public-key encryption is slow, so in practice it is used to agree on or protect a symmetric key, which then encrypts the real data. This combination is called hybrid encryption, and it is how HTTPS works.

Digital signatures

Signatures run the keys the other way round:

  1. Ada hashes a document and signs the hash with her private key.
  2. Anyone can check the signature with Ada's public key.
  3. If the check passes, the document came from someone holding Ada's private key, and it has not changed since it was signed.

Signatures give authenticity, integrity and non-repudiation. They protect software updates, emails (DKIM), certificates and documents.

Common algorithms

AlgorithmUsed for
RSAEncryption and signatures; keys of 2048 bits or more
Elliptic curve (ECDSA, Ed25519)Signatures with short keys and good speed
Diffie-Hellman (ECDHE)Two parties agreeing on a shared secret over an open network

Who owns this public key?

Public keys solve the sharing problem, but raise a new one: how do you know a public key really belongs to Ada, and not to an attacker pretending to be Ada? That question leads to certificates, in the next lesson.

Tip

SSH keys are key pairs. You put your public key on the server and keep the private key on your laptop, protected with a passphrase. Never copy a private key to a server or send it to anyone.