Two colleagues need to send each other a confidential file over the internet, where any computer along the way could keep a copy. How can they make every copy useless to anyone else?
Locking information
Encryption turns readable data, called plaintext, into scrambled data, called ciphertext. It uses an algorithm and a key. Decryption reverses the process and turns the ciphertext back into the original plaintext, but only for someone who holds the right key.
Without the key, good ciphertext should reveal nothing useful about the message, apart from roughly how long it is. Anyone can copy it, store it or pass it on, and it stays unreadable.
This is the difference from the hash functions in lesson 1.2. A hash is one way only and has no key. Encryption is designed to be reversed, by the right person.
One key, both directions
In symmetric encryption, the same secret key is used to encrypt and to decrypt. It's the symmetric key from lesson 1.1: a secret shared by the people or devices that use it. Like a door key, the same key that locks the box also opens it.
AES: today's standard
The most widely used symmetric algorithm today is the Advanced Encryption Standard, or AES. It was chosen through an open, public competition run by the U.S. National Institute of Standards and Technology (NIST) from 1997 to 2000, and published as a standard in 2001. That's Kerckhoffs's principle in action: the design is completely public, and two decades of scrutiny have found no practical attack on it when it's used correctly. Its security rests on the key.
AES keys can be 128, 192 or 256 bits long. AES is also fast. Most computer processors have built-in instructions for it, and secure chips, including those in many smart cards, can run it in hardware.
Two details that matter in practice
Encrypting data well takes more than an algorithm and a key. Two details make a big difference:
- A different nonce for every message. AES-GCM uses a public value called a nonce. Use a different nonce for every message encrypted with the same key; the receiver needs that nonce to decrypt. A counter can meet that rule, and so can a long random value, which makes a repeat extremely unlikely. Because the nonce differs, the same message encrypted twice gives two different ciphertexts, so an eavesdropper can't tell when a message repeats. Reusing a nonce with the same key can break GCM badly.
- Detecting tampering. Encryption hides the content, but on its own it doesn't stop someone from changing the ciphertext on the way. Modern systems use authenticated encryption, such as AES in GCM mode, which adds a check. If even one bit of the ciphertext has been changed, or the wrong key is used, decryption fails instead of producing a corrupted message.
Try it: lock and unlock a message
Your browser encrypts the message with AES-GCM and a random 128-bit key. Then try to decrypt it with the right key, a wrong key, or after changing one bit. Nothing is sent or stored.
…
…
…
Press Encrypt again to see the same message produce a different ciphertext, because each encryption uses a different nonce. The ciphertext is as long as the message, plus 16 bytes for the check.
The key-sharing problem
Symmetric encryption has one big catch. Before two people can use it, they have to establish the same secret key, and nobody else may learn it. One way is to provision it in advance: exchange a small key securely, in person or through a trusted channel, and then use it to protect files sent over an open network later.
That works for a few people, but it doesn't scale. If every pair of people needs its own key, a group of 10 needs 45 keys, and a group of 100 needs 4,950. Each one has to be set up, stored and eventually replaced.
Lesson 1.4 introduces public-key cryptography, which makes authenticated key agreement possible: two parties can establish a shared key over an open network, without ever sending the key itself, and check whom they're communicating with. In practice, most systems combine the two: public-key methods establish a fresh symmetric key, and fast symmetric encryption protects the actual data.
Symmetric keys in access cards
Many contactless access cards rely on symmetric keys. The card and the reader system share a secret key, and each side proves it holds the expected key. That shows possession of the key, not that the card is the original: a copy holding the same key can give exactly the same proof. So everything depends on where the key lives, and every place that holds it is a place it could leak from.
If one key is used in every card and every reader, extracting it from a single device can put the whole system at risk. Well-designed systems reduce this with key diversification: each card gets its own key, derived from a master key and data unique to the card, such as its serial number. A key leaked from one card then doesn't unlock the others, which limits the damage. The master key still has to be protected carefully wherever it's held.
Go deeperOptional technical detail for readers who want more
Block ciphers and modes
AES is a block cipher: it operates on 16-byte (128-bit) blocks. A mode of operation specifies how to use AES to protect a whole message. The simplest mode, ECB, encrypts each block separately with the same key, so identical blocks of plaintext produce identical blocks of ciphertext and patterns leak through; it shouldn't be used for messages. CBC chains each block into the next and needs an unpredictable IV (initialisation vector). CTR and GCM encrypt successive counter values, starting from the nonce, and combine them with the message; GCM also produces an authentication tag. NIST SP 800-38D specifies GCM; reusing a nonce with the same GCM key can expose data and allow forgeries.
Why key length matters: DES
Before AES, the standard was DES, with a 56-bit key. In 1998 the Electronic Frontier Foundation built a dedicated machine that found a DES key by brute force in 56 hours, which showed that 56 bits was no longer enough. Triple DES stretched DES's life by applying it three times, but NIST has since retired it for encryption. AES's shortest key, 128 bits, puts brute force far out of reach, as lesson 1.1 showed.
The card that fell: MIFARE Classic
The MIFARE Classic cards from lesson 1.1 used a secret symmetric cipher, Crypto-1, with a 48-bit key. Once researchers reconstructed the cipher, its design weaknesses and short key made keys recoverable in practice. Newer card families moved to published algorithms such as AES.
Try it yourself
With OpenSSL installed, this encrypts the word hello with AES-128 in CBC mode, using a random key and IV, and prints the ciphertext in hex:
$ printf 'hello' | openssl enc -aes-128-cbc -K $(openssl rand -hex 16) -iv $(openssl rand -hex 16) | xxd -p
Run it twice: the random key and the unpredictable IV give a different result every time. CBC has no built-in tamper check; the demo on this page uses GCM, which does.
Sources
Draft lesson, awaiting technical review · Last updated 19 November 2026