Choosing the Asymmetric Key
How public and private keys work as a pair, which key to use when sending or receiving encrypted data, and what to do when a private key is exposed.
1The problem asymmetric encryption solves
With symmetric encryption, sender and receiver need the same secret key, so they must agree on it in advance, somehow, without anyone overhearing. Asymmetric encryption lets people communicate securely without prearranging a shared secret key. That is how a browser can talk privately with a website it has never contacted before.
2Key pairs
Each entity that will receive encrypted data first generates a key pair: two binary strings of equal length, generated at the same time through a mathematical process. One is the public key, the other the private key. The keys are mathematical inverses: each key reverses its partner. Either key can encrypt, but only the other key in the pair can decrypt.
Real keys are thousands of bits long. A pair built from tiny numbers shows the idea (this is how RSA works, at toy size):
| Step | Computation | Result |
|---|---|---|
| Public key | (e, n) = (17, 2773) | Published for anyone |
| Private key | (d, n) = (157, 2773) | Kept secret by the owner |
| Encrypt the message 920 with the public key | 92017 mod 2773 | 948 |
| Decrypt with the private key | 948157 mod 2773 | 920 (the original) |
| Try to decrypt with the public key instead | 94817 mod 2773 | 1207 (garbage) |
| Encrypt with the private key | 920157 mod 2773 | 192 |
| Decrypt that with the public key | 19217 mod 2773 | 920 (the original) |
Both directions work, and in each case only the partner key undoes the lock. (“mod” means “keep the remainder after dividing by 2773.”)
3Which key do I use?
To send information securely to someone, the sender encrypts with the receiver's public key and sends it. Only the receiver, who holds the matching private key, can decrypt and read it.
| I want to… | Use this key | Why |
|---|---|---|
| Send a secret to Ben | Ben's public key | Only Ben's private key can reverse it |
| Read a secret sent to me | My private key | It reverses my public key, which the sender used |
| Let people send me secrets | Publish my public key | Sharing it is safe; it cannot decrypt what it encrypted |
| Reply to Aisha securely | Aisha's public key | Now Aisha is the receiver |
A quick check: the sender never uses their own keys to send a secret. Everything depends on the receiver's pair.
4Protecting the private key
Once the receiver generates the pair, the private key must be stored securely. The security of the whole system rests on it. If the private key is exposed, shared, stolen, corrupted, or compromised, the key pair must be deleted and a new key pair generated. The public key, on the other hand, is published for anyone to view and use.
To send someone a secret, encrypt with their public key; they decrypt with their private key. Public keys are shared freely; a private key never leaves its owner, and if it is ever exposed, replace the whole pair.
5Worked examples
Homework to the teacher
Dana wants to send her teacher, Mr. Hale, a file that only he can read. Both have key pairs. Which key should Dana use to encrypt, and which key will decrypt?
- 1Mr. Hale is the receiver, so his key pair is the one that matters.
- 2Dana encrypts with Mr. Hale's public key.
- 3Only Mr. Hale's private key can decrypt it.
The reply
Mr. Hale replies to Dana with her grade and wants only Dana to read it. Which key does he use?
- 1Now Dana is the receiver.
- 2He encrypts with Dana's public key; Dana decrypts with her private key.
Public key in the open
An attacker copies an encrypted message and also downloads the receiver's public key from the company website. Can the attacker read the message?
- 1The message was encrypted with the receiver's public key.
- 2The public key cannot reverse its own encryption; only the private key can.
- 3Publishing the public key is how the system is meant to work.
The private key on a shared drive
An employee discovers that their private key was accidentally saved to a shared drive that 200 coworkers can open. What should they do?
- 1The private key has been exposed, so anyone who copied it can decrypt messages sent to this employee.
- 2Deleting the copy is not enough; someone may already have it.
- 3Delete the key pair, generate a new one, publish the new public key, and tell senders to use it.
6Common mistakes
Then only you can decrypt it. To send to someone else, use their public key.
It is meant to be shared. Only the private key is secret.
Copies may exist. The whole pair must be replaced.
“To send the file to Ben securely, Aisha encrypts it with Ben’s public key. Because the two keys are mathematical inverses, only Ben’s private key can decrypt it, so an eavesdropper who has the public key still cannot read the file.”
Name the receiver, the key used to encrypt, the key used to decrypt, and why an outsider cannot read it.