Network Security

public-key cryptography

Imagine a special mailbox with two different keys. One key only locks it (and you give copies away to anyone — print it on your business card), and a second key only unlocks it (which you keep secret, forever). Now anyone in the world can send you a sealed message using the public lock-key, but only you, with the private unlock-key, can open it. The two keys are mathematically paired but you cannot work out the private one from the public one. That is the surprising and powerful idea behind public-key (asymmetric) cryptography.

Each party has a key pair: a public key, shared openly, and a private key, kept secret. The pair works two ways. For confidentiality: anyone encrypts with your public key, and only your private key decrypts — so you receive secrets without ever sharing a secret first. For authentication: you encrypt (sign) with your private key, and anyone can verify with your public key — proving the message came from you, since only you hold the private key. Crucially, this solves the key-distribution problem: two strangers can establish a shared secret over an open channel (a key exchange like Diffie-Hellman) without an eavesdropper learning it.

Why it matters, with an honest caveat: public-key cryptography is what lets total strangers communicate securely on the Internet without pre-arranging keys — it underpins TLS, digital signatures, and certificates. The catch is that it is slow — far slower than symmetric encryption — so it's almost never used to encrypt bulk data. Instead it's used briefly to agree on a fast symmetric key, then symmetric encryption takes over. There's also a deeper catch: a public key is just a number, so how do you know a given public key really belongs to your bank and not an impostor? Answering that is the job of certificates and certificate authorities.

A website publishes its public key in a certificate. Your browser uses it (via a key exchange) to agree on a fresh symmetric key that an eavesdropper can't compute, then both sides switch to fast AES for the rest of the session. Two strangers, no pre-shared secret — that's the public-key payoff.

Two paired keys solve key distribution — but are slow.

A public key alone proves nothing about whose it is. Without a way to bind a key to an identity (a certificate), an attacker can hand you their public key while claiming to be your bank — which is why PKI exists.

Also called
asymmetric cryptographyasymmetric encryption公開金鑰密碼學非對稱加密