Your browser can set up an encrypted connection with a server it has never contacted before, without either side sending the shared secret over the network. The trick is to exchange public information that helps both sides compute the same secret, while each side keeps its private key to itself.
That solves only part of the problem. If someone can swap the public information in transit, your browser could set up an encrypted connection with the wrong party. Public-key cryptography gives protocols tools for both jobs: establishing a shared secret and checking who is on the other end.
What the public key lets other people do
A public key and its matching private key are mathematically linked. The public key is safe to distribute, but someone who has only that key should find it impractical to work out the private one. What people can do with the public key depends on what the algorithm was designed for:
- Encrypt a message. A sender uses the recipient's public key to encrypt it. The recipient uses the matching private key to read it. That hides the message, but it doesn't prove who sent it: anyone can use the public key.
- Verify a signature. A signer uses a private key to sign data. Anyone with the matching public key can check that the signature covers that exact data, without gaining the ability to sign anything themselves. The data doesn't become secret.
- Establish a shared secret. In a Diffie–Hellman-style exchange, each side combines its own private key with the other side's public key to compute the same secret. A key encapsulation mechanism, or KEM, takes a different route: the sender uses the recipient's public key to produce a secret and an encapsulation, a piece of data safe to send. The recipient uses its private key to recover the same secret from that data.
Once both sides have the secret, they can derive keys for symmetric encryption, where both sides use the same key for a given direction of traffic. That handles the bulk data efficiently. The public-key work gets the connection started rather than encrypting every byte that moves through it.
An encrypted connection can still reach the wrong server
Suppose your browser takes a server's public key at face value. Someone in the middle can substitute their own key and set up separate encrypted connections with the browser and the real server. The traffic is encrypted on both links, but the intermediary can read it between them.
A signature can prove that the sender holds a private key. It can't tell you whose key it is unless you already trust the link between that key and an identity.
In HTTPS, a certificate links a public key to a domain name. The browser checks the name against the site it requested and verifies a chain of signatures back to a certificate authority it already trusts. The server then uses the matching private key to sign handshake data, which ties its identity to the connection being set up.
What a post-quantum switch replaces
Public-key algorithms rely on maths problems that are hard to solve with the computing methods an attacker has available. A sufficiently capable quantum computer could solve the problems behind widely used public-key algorithms such as RSA and elliptic-curve cryptography. The risk depends on the job: breaking key establishment can expose secrets behind recorded traffic, while breaking a signature algorithm can make forgeries possible.
Post-quantum algorithms use different maths problems, chosen because there are no known efficient attacks against them using either classical or quantum computers. The distinction between jobs still holds: a post-quantum KEM can replace a way of establishing a secret, but it doesn't replace the signature used to authenticate the other side. Switching one doesn't switch the other.
Where you meet public keys in practice
You meet public-key cryptography when HTTPS checks the server's identity and sets up an encrypted connection, when SSH checks a host key before you log in, and when a package manager verifies a repository's signed metadata before installing software. The useful debugging question is which job the key is doing. A certificate name mismatch is an identity failure, not a sign that the encryption itself has stopped working.




