# Public-Key Cryptography

> Two keys that work as a pair. One is shared, and one is kept secret.

**Field:** Software Development  
**Category:** Security  
**Also known as:** Asymmetric Encryption, Asymmetric Cryptography, Key Pair, Public and Private Keys

## Think of it like

Think of it like a mailbox. Anyone can drop a letter in, but only you have the key.

## Definition

Public-key cryptography uses a pair of keys that work together. The public key can be shared with anyone. The private key is kept secret by its owner. Data locked with the public key can only be opened with the private key. It also works the other way round, which is how digital signatures prove who sent something. HTTPS, SSH and passkeys are all built on it.

## Example

Emma puts her public key on a server. When she logs in, the server sends a test that only her private key can answer.

## Example code

```console
$ ls ~/.ssh
id_ed25519  id_ed25519.pub
```

Two halves of one key pair. The .pub file is shared, and the other one stays secret.

## Why it matters

It lets two strangers talk safely without first meeting to share a secret. The secure web depends on it.

## Common mistake

Sending someone your private key so they can check your work. Only the public key is ever shared.

## Three principles

- **Two keys.** One public, one private.
- **Lock and unlock.** What one locks, only the other opens.
- **Share only the public one.** The private key never leaves you.

## Related terms

- [Encryption](https://learn.benibix.com/term/development/encryption)
- [Digital Signature](https://learn.benibix.com/term/development/digital-signature)
- [Passkey](https://learn.benibix.com/term/development/passkey)
- [Hashing (Cryptography)](https://learn.benibix.com/term/development/hashing)
- [Transport Layer Security (TLS)](https://learn.benibix.com/term/infrastructure/tls)
- [Crypto Wallet](https://learn.benibix.com/term/development/crypto-wallet)

![Two rows. To keep a secret: anyone locks a message with Emma's public key, it becomes scrambled, and only Emma's private key, lit up, opens it. To prove who sent it: Emma signs with her private key, lit up, the message travels with a signature, and anyone checks it with Emma's public key.](https://learn.benibix.com/diagrams/dev2-public-key.svg)

---

Source: https://learn.benibix.com/term/development/public-key-cryptography
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
