Public and private keys in 3D

A standing 3D comparison board contrasting symmetric encryption with one secret key and asymmetric encryption using shared public and secret private keys.Drag to turn

Private key (symmetric) cryptography uses one secret key for both encryption and decryption. Public key (asymmetric) cryptography uses a mathematically linked pair, where a public key can be shared openly and a private key is kept secret.

Two ways to lock a message

The padlock analogy helps. In symmetric cryptography, one key both closes and opens the padlock, so both parties need a copy of it. Examples include AES, which is widely used for encrypting data.

In asymmetric cryptography, each person has a key pair. The public key works like an open padlock that anyone can snap shut. Only the matching private key can open it. Examples include RSA and elliptic curve schemes.

How the key pair works

The two keys are linked by a mathematical problem that is easy to compute in one direction and very hard to reverse. RSA relies on the difficulty of factoring a large number into its primes. Knowing the public key does not let an attacker practically work out the private key when key sizes are chosen properly.

For confidentiality, a sender encrypts with the recipient's public key, and the recipient decrypts with the private key. For digital signatures, the signer uses the private key, and anyone can check the result with the public key.

A worked case: sharing a secret with ten people

Suppose a group of 10 people wants each pair to communicate privately using symmetric keys. The number of pairs is 10 x 9 / 2 = 45 keys, and each key must first be delivered by a safe route.

With public key cryptography, each person holds one key pair. That is 10 key pairs, and the 10 public keys can be published openly. Anyone can then send an encrypted message to anyone else without a prior secret exchange.

Common misconceptions

One belief is that public key cryptography replaces symmetric cryptography. It usually does not. Asymmetric operations are much slower, so systems typically use them to agree on or protect a symmetric session key, and then encrypt the bulk data with the symmetric cipher.

Another belief is that a public key proves who owns it. It does not by itself. Certificates issued by certificate authorities bind a public key to an identity, and a user must still trust that authority. The private key must also not be shared, because anyone holding it can decrypt messages or forge signatures.

Where it shows up

HTTPS uses TLS, which relies on public key methods to authenticate a server and establish a session key. SSH uses key pairs to log in to remote machines. Software and code signing depend on digital signatures.

Key terms

Symmetric cryptography
A method in which the same secret key encrypts and decrypts data.
Asymmetric cryptography
A method that uses a linked public key and private key.
Public key
The key in a pair that can be shared openly.
Private key
The key in a pair that its owner keeps secret.
Digital signature
A value created with a private key that anyone can verify with the matching public key.
Certificate
A signed document that links a public key to an identity.
Session key
A temporary symmetric key used to encrypt the data of one communication session.

Common questions

Can a message encrypted with a public key be decrypted with the same public key?

No. In an encryption scheme, data locked with the public key is opened only with the matching private key.

Why not use public key cryptography for everything?

Asymmetric operations are far slower than symmetric ones and are less suited to large amounts of data. Systems usually use asymmetric methods to set up a symmetric key, then switch to a fast symmetric cipher.

What happens if a private key is stolen?

The thief can decrypt messages meant for the owner and can forge signatures in the owner's name. The key should be revoked, any certificate for it replaced, and a new pair generated.

Learn this with a tutor

Sidechair's AI tutor will teach this topic in 3D. Join the waitlist for early access.

We'll only email you about Sidechair. Read our privacy policy.