bastion

Asymmetric-Key Encryption

Build this skill

Explain which key of a pair locks and which unlocks, and decide when a key pair, a symmetric key or both should do the work.

A lock anyone can close but only one person can open

Rathi Softech, the vendor in Indore that supplies MedLedger, needs to send Tulsi Health a new licence file containing a secret activation code. The two companies have never met in person and share no secret key, and the only road between them is the internet, where anyone might be copying the traffic. With symmetric encryption alone this is a dead end, because the key would have to travel the same road as the data. Asymmetric-key encryption gets around it by using two different keys instead of one: a key that locks, which can be handed to anyone, and a different key that unlocks, which never leaves its owner. It is the idea that makes it possible for strangers to talk privately on the internet.

slot TULSI HEALTH locked door Rathi Softech Mrs. Gokhale Public key = the slot Anyone can drop a message in. Shared openly with the world. Tulsi Health (the postmaster) Private key = the door key Only its owner can take letters out. Never shared, never sent. A passer-by can see the slot, but cannot open it.

The slot is open to everyone and the door key belongs to one owner. Knowing where the slot is gives a passer-by nothing they can use to read the letters inside.

Key pairs: two keys that belong together

Think of a post-office letterbox. Anyone walking past can drop a letter through the slot, and nobody needs permission or a key to do it. But once a letter falls in, only the postmaster with the key to the little door at the bottom can take it out. Not even the person who posted the letter can reach in and pull it back. Asymmetric encryption works the same way, with the slot and the door key replaced by two related numbers.

Those two numbers are created together, by the owner's computer, as a key pair. One is the public key, the slot: the owner publishes it freely, on a website, in an email signature, or by sending it to anyone who asks. The other is the private key, the door key: it stays on the owner's own device and is never sent to anyone. Whatever is encrypted with the public key can be decrypted only with the matching private key. The two keys are linked by mathematics that is easy to run in one direction and practically impossible to reverse, so even with the public key in hand, nobody can work out the private key from it.

Because one key encrypts and a different key decrypts, this family of methods is called asymmetric, or public-key cryptography. The best known are RSA, published in 1977 and still widely used, and newer methods based on elliptic curves, which reach the same strength with much shorter keys. You do not need the mathematics to use them safely. You only need to remember which key goes where: the public key is shared to let others lock things for you, and the private key is guarded because it opens them.

Licence fileplaintext at RathiCiphertextcrosses the internetTulsi's private keyLicence fileread at Tulsi onlyLock with the receiver's public key; only the receiver's private key unlocks.

Rathi Softech never needs a secret of its own to send something private. It uses Tulsi Health's public key, which anyone may have.

Solving the key exchange

Now go back to the licence file. Tulsi Health makes a key pair and sends its public key to Rathi Softech openly, even by plain email. Rathi Softech encrypts the licence file with that public key and sends the ciphertext. A snooper who copies everything on the line ends up holding the public key and the ciphertext, and neither helps: the public key only locks, and the ciphertext opens only with the private key, which never left Tulsi Health's server. No secret ever travelled.

Step through the exchange below in three versions: first with a symmetric key sent by email, then with a key pair, and finally the way real systems combine the two. Some steps pause and ask you to predict what the snooper can do, so think about which keys they hold at each point.

Why not use key pairs for everything

If key pairs solve the exchange so neatly, why keep symmetric encryption at all? The answer is speed. Public-key encryption relies on heavy arithmetic with very large numbers, and it is much slower than AES, often by a factor of hundreds or more. Its keys are also far longer for the same strength: an RSA key is typically 2,048 bits or more, where AES is just as strong at 128. Encrypting a 2 GB software update or a nightly backup with a key pair would be painfully slow.

So real systems do both, an approach called hybrid encryption. The key pair is used once, at the start, to deliver a fresh random AES key safely. After that, all the actual data is encrypted with AES. It is like using a registered post envelope to send the key of a dabba once, and then sending the daily dabbas by any ordinary delivery boy.

Symmetric (e.g. AES)One shared key locks and unlocksVery fast, good for bulk dataKey must be delivered safelyKeys of 128 or 256 bitsAsymmetric (e.g. RSA)Public key locks, private unlocksSlow, used for small secretsPublic key can be sent openlyKeys of 2,048 bits or more

Each covers the other's weakness, which is why secure connections use both: a key pair to agree a key, then AES for the data.

Where key pairs are used, and how they fail

Key pairs are at work every time a phone or browser opens a secure connection to a website: the first moments of the connection use the server's public key to agree a fresh AES key. Secure messaging apps give each phone its own key pair, so messages can be locked for a contact's phone alone. Rohan Iyer logs in to the Tulsi Health app's cloud server with a key pair instead of a password: the server keeps his public key, and his laptop proves it holds the matching private key. Key pairs can also be used the other way round, with the private key making a mark on a message that anyone can check with the public key, which is how a MedLedger update can prove it really came from Rathi Softech.

PhoneWebsiteHere is my public key1New AES key, locked with it2Opened: both share AES key3All data now sent with AES4

The key pair is used for a moment at the start; AES carries everything after that.

The weak points are, once again, about keys. If a private key leaks, for example when a developer accidentally uploads a laptop folder containing it to a public code-sharing site, anyone can read what was locked for its owner or pretend to be them, and the pair must be replaced at once. If a private key is lost with no backup, data locked to it cannot be recovered. And there is a subtler trap: when Rathi Softech receives a public key labelled "Tulsi Health", how does it know the key is really Tulsi's and not a snooper's own key, swapped in on the way? In practice, public keys arrive inside digital certificates, electronic documents in which a trusted organisation vouches that a public key belongs to a particular name.

Sort the jobs below by which kind of encryption does the main work. Remember the rule of thumb: large amounts of data, or data that stays in one place, usually go to the fast symmetric cipher, while first contact between strangers needs a key pair.

Follow your curiosity.

โ†‘ โ†“ to explore ยท Enter to open ยท Escape to close