Brief Overview of Encryption
Encryption is the mathematical science of codes, ciphers, and secret messages. Throughout history, people have used encryption to exchange messages that, they hoped, could only be read by the intended recipients. Today, computers can perform encryption, and digital encryption technologies have moved far beyond simple secret messages. Encryption is now used for more complex tasks, such as verifying the identity of a message sender or anonymously browsing websites using the Tor network. Under certain conditions, encryption can be fully automatic and easy to use. However, if something goes wrong, it’s helpful to understand the basics—this way, you’ll be better protected against problems.
Encryption: Three Key Concepts
- Private and Public Keys
One of the most important concepts in encryption is the key. Common encryption schemes use a private key, which is kept secret on your computer and allows you to read messages addressed to you. The private key can also be used to place a tamper-proof digital signature on outgoing messages. The public key is a file you can share with others. It allows them to send you encrypted messages and verify your signatures. Private and public keys are paired and dependent on each other. - Security Certificates
The second crucial concept is the security certificate. This is a kind of public key used to prevent man-in-the-middle attacks. A website with access to a certificate can demonstrate to remote systems that the certificate exists and that no other system (without the certificate) is trying to alter the transmitted data. Your web browser can establish encrypted connections with websites using the HTTPS protocol. In such cases, the browser verifies certificates by checking the public keys of domain names (like www.google.com or www.amazon.com). Using certificates is one way to confirm the authenticity of a user’s or website’s public key so you can safely exchange information.
Occasionally, you may see a security certificate error. Usually, this is caused by a public Wi-Fi hotspot trying to “break open” your encrypted data exchange with a website. Such errors can also result from bureaucratic issues in the certificate system or from an attacker trying to compromise your encrypted connection.
Unfortunately, it’s extremely difficult to determine the true cause of a certificate error. Therefore, when you encounter such an error, you should never make exceptions for sites where you have an account or receive especially important information. - Key Fingerprints
Keys in public-key encryption systems are very large numbers, sometimes over a thousand digits long. A key fingerprint is much shorter. It’s a number (a set of numbers and letters) that uniquely identifies a key and allows you to verify its authenticity without checking every character. Suppose you and your contact exchange copies of your keys and then want to make sure the copies match the originals. Comparing every character would take a lot of time. Instead, you can compare key fingerprints. Modern encryption tools usually use fingerprints that are 40 characters long, for example: 5d44 4rt8 9167 7401 40dl 5ws4 200z q561 23sd yl91. If you carefully compare the imported key’s fingerprint with the one provided by the real owner, you can be confident in the key’s authenticity (some programs offer even more convenient ways to check keys).
If the fingerprint matches, it’s more likely your contact is who they claim to be. However, this method isn’t perfect—an attacker could use the same fingerprint if they copy or steal the key.
Basics of PGP Encryption
PGP encryption (Pretty Good Privacy) is one of the first popular implementations of public-key encryption, created by programmer Phil Zimmermann in 1991 to help users protect their communications. When used correctly, PGP can protect the contents of your messages and even files from the most advanced attackers. When Edward Snowden talked about encryption, he was referring specifically to PGP and related programs.
Public-Key Encryption
Traditional encryption tools use the same key for both encrypting and decrypting a message. Asymmetric encryption (public-key encryption) uses two paired keys: one for encryption (public) and one for decryption (private). This has many advantages. For example, you can share your public key with everyone. As long as you have access to your private key, anyone with your public key can communicate with you securely. Such systems are used to encrypt emails and files according to PGP standards, OTR (for instant messaging), and SSL/TLS (for browsing web pages).
Unfortunately, PGP isn’t the easiest tool to learn and use. The strong encryption implemented in PGP (public-key encryption) is powerful but quite complex. The PGP program itself has been around for a quarter of a century and is as old as the earliest versions of Microsoft Windows. Since then, PGP’s appearance hasn’t changed much. However, many programs have been developed to hide PGP’s “old-school” design and make it much easier to use, especially for encrypting and authenticating email (PGP’s main functions). You’ll learn to use these programs later. But first, let’s spend a few minutes on the basics of public-key encryption.
The Two-Key System
Let’s take a simple text—say, “Hello, friend!”—and encrypt it, turning it into a code unreadable to outsiders (for example, ad&dsDE76vx+fdgQl). We send this code over the Internet. Many people might see our message, but who can understand its content? In this form, the message reaches the recipient, and only they can decrypt and read the original text. How does the recipient know how to decrypt the message if no one else can? The recipient has extra information unavailable to others—a decryption key. This key decodes the text in the encrypted message. But the sender must first provide the key to the recipient. This is the flaw in such a strategy—if you think your mail might be intercepted, how do you send the key? An attacker could intercept it, making encrypted messages pointless. On the other hand, if you have a secret way to send the key, why not use it to send all your secret messages?
Public-key encryption is a great solution to this problem. Each person in the conversation creates two keys. One key (private) must be kept secret and never shared. The other key (public) can be given to anyone who wants to communicate. It doesn’t matter who gets access to the public key. You can publish it on the web for anyone to download. The “keys” themselves are actually very large numbers with certain mathematical properties. The public and private keys are linked—if you encrypt something with the public key, only the paired private key can decrypt it.
Suppose you want to send your friend a secret message. They have a private key and a matching public key posted on their website. You download their public key, use it to encrypt your message, and send it to them. Only they can decrypt the message, because only they have the matching private key.
Digital Signatures
Public-key encryption solves the problem of sending the recipient a decryption key (the recipient already has it). You only need to get the appropriate public key for encryption—it’s available to anyone, even attackers. But the public key can only encrypt, not decrypt.
So, anything encrypted with a specific public key can only be decrypted with the matching private key. But there’s more. If you use your private key on a message, the result can only be processed with the matching public key. Why do this? It might seem pointless to “protect” a secret message with your private key, since anyone with your public key (which is public) can remove the protection. But suppose you write “Hello, Andrey!” and use your private key on this text. Anyone can then read the message using your public key, but only one person (and this is key!) could have written the message—the owner of the private key, assuming they keep it safe. This lets you confirm authorship.
A signature also protects the message from being edited. If someone tries to change “Hello, Andrey!” to “Hello, Vlad!” they won’t be able to re-sign the message (they don’t have your private key). Thus, a digital signature guarantees that the message was truly written by its author and hasn’t been altered in transit.
In summary, public-key encryption lets you encrypt and securely send messages to anyone whose public key you know. If others know your public key, they can send you messages that only you can decrypt. You can also sign messages, so anyone with your public key can verify your emails’ authenticity. If you receive a message with someone’s digital signature, you can use the sender’s public key to confirm they wrote it.
As you might guess, the more people know your public key, the more useful public-key encryption becomes. It’s also clear that you must keep your private key safe—if someone gets a copy, they can impersonate you and sign messages in your name. PGP includes a key revocation feature to warn people that a key is no longer trustworthy, but this isn’t ideal. The main rule for public-key encryption: keep your private key in a secure place.
How PGP Works
Using PGP mainly involves creating and using public and private keys. With PGP, you can create a key pair (public/private), protect your private key with a password, and use the keys to sign and encrypt messages. PGP-based programs also let you download other users’ public keys and upload your own public key to servers where others can find it.
So, you keep your private key in a safe place and protect it with a strong password. The public key can be given to anyone you want to communicate with, and to those who want to verify your emails’ authenticity.
Web of Trust
Public-key encryption has a potential problem. Suppose you distribute Edward Snowden’s public key (or at least claim to). If people believe you, they’ll start sending Snowden messages encrypted with that key. They’ll also assume that all messages signed with that key were created by Snowden. This is rare, but it has happened in real life. There’s also a possible attack scenario where an attacker sits between two people, reads their messages, and occasionally inserts confusing messages. The Internet is designed so that information passes through many different computers, making such a “man-in-the-middle” attack possible. Because of this, exchanging keys without prior arrangements is risky. “Here’s my key,” says Edward Snowden, and sends you his public key. What if a middleman intercepts Snowden’s key and replaces it with their own? How can you be sure the key really belongs to the person you think?
Of course, you could get the key directly from the person, but that’s not much easier than exchanging a single key and protecting it from interception. Still, the most reliable way to prevent interception is to exchange public keys in person.
Man-in-the-Middle Attack
Imagine you’re chatting with your friend (let’s say, Dmitry) using encrypted instant messages. To make sure it’s really Dmitry, you ask your contact to name the city where you first met. “Magadan,” he replies. Correct! Unfortunately, without your knowledge, someone else is intercepting your messages. Your messages to Dmitry go to the attacker, who then communicates with Dmitry, and vice versa. You think you’ve set up a secure channel, but you’re actually talking through a spy! This is called a man-in-the-middle attack. The attacker can intercept, modify, and forge messages. That’s why Internet communication programs must protect against this type of attack, from attackers who might control part of the network infrastructure between you and your contact.
Nevertheless, PGP offers a better solution—a web of trust. If you believe a key belongs to a certain person, you can sign that key and upload it (with your signature) to a public key server. Others can then download the signed key. In general, the more people you trust who sign a key, the more trustworthy it becomes. PGP lets you sign others’ keys and trust other users—if they sign a key, your program will automatically consider it valid. Of course, the web of trust isn’t perfect. But today, unless you’re ready to exchange keys only in person, using the web of trust and public key servers is the best alternative.