This article is free to read. Creating a lesson uses your daily or stored credits; review the language and settings before starting.
How does public-key cryptography work?
Quick answer
Public-key cryptography uses a pair of keys: a public key that can be shared openly and a private key kept secret. Anyone can encrypt a message with the public key, but only the matching private key can decrypt it. The keys are linked by a one-way mathematical function that is practically impossible to reverse.
Public-key cryptography works by giving each person two mathematically linked keys: a public key anyone can use to encrypt a message, and a private key only the owner holds to decrypt it. The security rests on the fact that deriving the private key from the public key is computationally infeasible.
Step by step
- Each user generates a mathematically linked pair of keys: a public key and a private key.
- The public key is published or shared freely, while the private key is kept secret.
- A sender encrypts a message using the recipient's public key.
- The encrypted message is sent over an insecure channel, such as the internet.
- The recipient decrypts the message using their private key, which only they possess.
- For authentication, the sender can sign a message with their private key, and anyone can verify it with the public key.
Key things to understand
- Each user generates a key pair: a public key shared openly and a private key kept secret.
- The keys are related by a one-way mathematical function that is easy to compute but practically impossible to reverse.
- To send a secret message, the sender encrypts it with the recipient's public key.
- Only the recipient's private key can decrypt that message, so eavesdroppers cannot read it.
- The same key pair can also create digital signatures: signing with the private key lets anyone verify with the public key.
Labelled diagram
- Key generation
A user creates a linked public key and private key using a one-way function.
- Public key shared
The public key is distributed openly; the private key remains secret.
- Encryption
Sender encrypts a message with the recipient's public key.
- Transmission
The encrypted message travels over an insecure channel.
- Decryption
Recipient uses their private key to decrypt and read the message.
Real-world examples
- When you visit a website using HTTPS, your browser uses the site's public key to establish a secure session.
- Messaging apps like Signal use public-key cryptography to encrypt messages end-to-end.
- Software developers sign code releases with their private keys so users can verify authenticity.
- Cryptocurrencies like Bitcoin use public-key cryptography to create wallet addresses and authorize transactions.
Common mistake
✗ Myth: Public-key cryptography means you can encrypt with either key and decrypt with the other.
✓ Fact: In standard public-key encryption, you encrypt with the public key and decrypt with the private key. For digital signatures, the process is reversed: you sign with the private key and verify with the public key.
People also ask
What is public key cryptography used for?
How are public and private keys related?
Can someone guess my private key?
What is the difference between symmetric and public-key encryption?
How does a digital signature work?
Why is public-key cryptography considered secure?
What happens if my private key is stolen?
Part of the guide: How the Internet Works →

