Skip to content
Know.itKnow.it
Create an animated lesson
On request

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?

TechnologyLesson on requestFree to read

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

  1. Each user generates a mathematically linked pair of keys: a public key and a private key.
  2. The public key is published or shared freely, while the private key is kept secret.
  3. A sender encrypts a message using the recipient's public key.
  4. The encrypted message is sent over an insecure channel, such as the internet.
  5. The recipient decrypts the message using their private key, which only they possess.
  6. 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

  1. Each user generates a key pair: a public key shared openly and a private key kept secret.
  2. The keys are related by a one-way mathematical function that is easy to compute but practically impossible to reverse.
  3. To send a secret message, the sender encrypts it with the recipient's public key.
  4. Only the recipient's private key can decrypt that message, so eavesdroppers cannot read it.
  5. The same key pair can also create digital signatures: signing with the private key lets anyone verify with the public key.

Labelled diagram

  1. Key generation

    A user creates a linked public key and private key using a one-way function.

  2. Public key shared

    The public key is distributed openly; the private key remains secret.

  3. Encryption

    Sender encrypts a message with the recipient's public key.

  4. Transmission

    The encrypted message travels over an insecure channel.

  5. Decryption

    Recipient uses their private key to decrypt and read the message.

How public-key encryption works

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?
Public-key cryptography is used for secure communication over the internet, such as HTTPS websites, email encryption, and messaging apps. It also enables digital signatures, which verify the authenticity and integrity of software updates, documents, and cryptocurrency transactions.
How are public and private keys related?
Public and private keys are mathematically linked by a one-way function. It is easy to compute the public key from the private key, but practically impossible to derive the private key from the public key. This asymmetry is what makes the system secure.
Can someone guess my private key?
Guessing a private key is practically impossible with current technology because the key space is enormous. For example, a 2048-bit RSA key has more possible values than there are atoms in the observable universe. However, poor key management or weak random number generation can compromise security.
What is the difference between symmetric and public-key encryption?
Symmetric encryption uses one shared secret key for both encryption and decryption, so both parties must already share it securely. Public-key encryption uses two keys, allowing secure communication without prior shared secrets, but it is slower and often used only to exchange a symmetric key.
How does a digital signature work?
A digital signature is created by hashing the message and processing that hash with the sender's private key. Anyone can check the signature with the sender's public key against a fresh hash of the message, proving the message came from the sender and was not altered.
Why is public-key cryptography considered secure?
Its security relies on the computational difficulty of certain mathematical problems, such as factoring very large numbers or solving discrete logarithms. For well-chosen key sizes, solving these problems would take impractical amounts of time with current computers.
What happens if my private key is stolen?
If your private key is stolen, an attacker can decrypt messages meant for you and forge your digital signature. You should revoke the key pair immediately, generate a new one, and notify anyone who relies on your public key.

Part of the guide: How the Internet Works →