Privacy note: We capture your IP address to provide customised and focused services. See our Privacy Policy.

Cybersecurity Essentials — Alpha School

Lesson 11: Asymmetric Encryption and Digital Signatures

Asymmetric encryption solves the key distribution problem with a clever trick: instead of one shared secret, each person has two keys that belong together, a public key they can share with anyone, and a private key they keep secret. Anything encrypted with the public key can only be decrypted with the private key, so anyone can send you a secret message, but only you can read it, and the two keys are linked by maths that makes it practically impossible to work out the private key from the public one. This lesson explains how that works, introduces RSA and elliptic-curve cryptography, and shows how the same idea, run in reverse, creates digital signatures, which prove who wrote a message and that it has not been changed.

Public and private keys

The key idea is that the two keys do opposite jobs. To send a secret message, you encrypt it with the receiver's public key, and only the receiver's private key can decrypt it, so the public key can be published in a directory or on a website without any risk. The maths behind this is based on problems that are easy in one direction and hard in the other: RSA, the oldest widely used system, relies on the difficulty of factoring a large number into its two prime factors, while elliptic-curve cryptography relies on a different hard problem and achieves the same strength with much shorter keys, which is why it is popular on phones. In practice, asymmetric encryption is slow, so it is used to exchange a symmetric key, and the symmetric cipher then does the fast work, which is the partnership you will see inside TLS.

Digital signatures: the reverse trick

Run the keys in the other direction and you get a digital signature. To sign a message, you use your private key, and anyone can verify the signature with your public key, which proves two things: that the message came from the holder of the private key, and that it has not been changed since it was signed, because any change breaks the signature. Signing usually works on a hash of the message rather than the whole message, which is faster and just as secure, and the signature is attached to the message for anyone to check. This is how software updates are verified, how websites prove their identity in TLS, and how contracts can be signed digitally: the signature is the proof, and the public key is the way to check it, and neither requires trusting the channel the message travelled through.

Trusting a public key

Asymmetric cryptography has one problem of its own: how do you know a public key really belongs to the person it claims to? An attacker could publish their own key and claim it is a bank's, and anyone who used it would be encrypting messages for the attacker. The solution used on the web is certificates, which are public keys bundled with identity information and signed by a trusted authority, called a certificate authority, and your browser carries a list of authorities it trusts, so it can check a site's certificate automatically. For personal use, the solution is simpler: exchange public keys in person, or check a key's fingerprint, a short string derived from the key, through a channel you trust, such as a phone call, before you rely on it. Trust is not a technical detail here, it is the whole point, and a key you have not verified is a key you should not trust.

When to use which kind

The rule of thumb is simple: use asymmetric cryptography to set up trust and exchange keys, and symmetric cryptography to encrypt the actual data. When you visit a website, your browser uses the site's public key to agree on a symmetric key in secret, and then the symmetric cipher encrypts the conversation, because it is thousands of times faster. When you sign a document, you use your private key to sign its hash. When you store files on your own disk, you use symmetric encryption with a key derived from your password, because there is nobody to exchange keys with. Knowing which tool fits which job is the skill, and the two kinds of cryptography are partners, not rivals, each doing the job the other cannot.

Key Terms

Asymmetric encryption
Encryption using a pair of keys: a public key anyone can use to encrypt, and a private key only the owner holds to decrypt.
Public key
A key that can be shared openly; anything encrypted with it can only be decrypted by the matching private key.
Private key
A key that must be kept secret; it decrypts messages encrypted with the matching public key, and it creates signatures.
RSA
A widely used asymmetric system based on the difficulty of factoring large numbers.
Elliptic-curve cryptography
An asymmetric system that achieves the same strength as RSA with much shorter keys.
Digital signature
A value made with a private key that proves who wrote a message and that it has not been changed.
Certificate authority
A trusted organisation that signs certificates binding a public key to an identity.

Discussion Questions

  1. Why can a public key be published openly without any risk?
  2. How does a digital signature prove both who wrote a message and that it was not changed?
  3. If an attacker publishes their own key claiming it is a bank's, what goes wrong, and how do certificates prevent it?

Practice Questions

  1. How do public and private keys work together to send a secret message?
  2. Why is asymmetric encryption slower than symmetric encryption?
  3. What does a digital signature prove?
  4. What is a certificate authority for?
  5. When should you use asymmetric cryptography, and when symmetric?
Show answers
  1. Anyone encrypts with the receiver's public key, and only the receiver's private key can decrypt it. The public key can be shared openly, while the private key stays secret.
  2. Because the maths behind it is far heavier. In practice it is used to exchange a symmetric key, and the symmetric cipher then does the fast work.
  3. That the message came from the holder of the private key and has not been changed since it was signed. Anyone can verify it with the public key.
  4. It signs certificates that bind a public key to an identity. Your browser trusts a list of authorities, so it can check a site's certificate automatically.
  5. Asymmetric to set up trust and exchange keys; symmetric to encrypt the actual data. The two work as partners, each doing the job the other cannot.
Keep reading to complete this lesson