Network security

How Does Public-Key Cryptography Work? Keys, Signatures and TLS

Two keys, one secret and one shared, protect almost everything you do online. Here is how they work, where they are used, and what can go wrong.

Cysoro Security TeamPublished · 10 min read
NETWORK SECURITYPublic-keycryptographyTwo keys. One secret. One shared.PUBPublic keyshared openlyKEYPrivate keykept secret
Quick answer

Public-key cryptography uses a mathematically linked pair of keys. Anyone can use your public key to encrypt a message for you or to verify a signature you made, but only your private key can decrypt that message or create that signature. Because the private key cannot feasibly be derived from the public key, strangers can communicate securely without first sharing a secret.

Key takeaways

  • A public key encrypts and verifies; a private key decrypts and signs, and the private key must stay secret.
  • Public-key cryptography usually protects a short symmetric key, not whole files, because it is slow.
  • Certificates and public-key infrastructure bind a public key to an identity, so you know whose key you are using.

Every time you open a secure website, send an encrypted message or install a signed update, public-key cryptography is doing quiet work in the background. It solves a problem that looks impossible: how do two strangers exchange secrets when anyone can listen in?

What is public-key cryptography?

Public-key cryptography is a system that uses two mathematically linked keys: a public key you share openly and a private key you keep secret. Data encrypted with one key can only be handled by the other key in the pair.

NIST defines it as cryptography that uses two separate keys to exchange data, one to encrypt or digitally sign the data and one to decrypt the data or verify the digital signature. It is also called asymmetric cryptography, because the two sides do not use the same key. You can read NIST's full definition in its public-key cryptography glossary entry.

The link between the keys is a one-way function. It is easy to derive the public key from the private key, but computationally infeasible to work backwards from the public key to the private key. That one-way property is the whole trick.

Think of the public key as an open padlock. Anyone can snap it shut on a box addressed to you. Only you hold the key that opens it. A signature works the other way: only you can stamp a document with your private seal, but anyone can check the stamp against your public seal.

How does public-key cryptography work?

It works in three steps: generate a key pair, share the public key, and use each key for its own job. The private key never needs to travel, which is what makes the system practical.

How a key pair works1Generate a pairpublic key + private keylinked by hard math2Share the public keypublish it, or put itin a certificate3Use each key oncepublic encrypts, privatedecrypts; private signsThe private key never leaves its owner. That is the point.
The three steps of public-key cryptography. Illustration by Cysoro.

Step 1: Generate a key pair

You or your software generate a random private key, then derive the matching public key from it. Good randomness matters: a predictable private key is a broken private key.

Key generation happens in browsers, operating systems, password managers and certificate tools. You rarely see it, but you rely on it every time a device creates a passkey or a server gets a certificate.

Step 2: Share the public key

You can publish the public key anywhere: on a website, in a certificate, in a DNS record or sent directly to a contact. Sharing it does not weaken security, as long as nobody can silently replace it with their own key.

That replacement risk is why certificates exist. A certificate binds a public key to a name, such as a website, and is signed by a trusted certificate authority. Your browser checks that chain before it trusts the key.

Step 3: Encrypt, decrypt, sign and verify

To send you a secret, someone encrypts it with your public key. Only your private key can decrypt it, so even the sender cannot read it back afterwards. To prove a message came from you, you sign it with your private key, and anyone can verify that signature with your public key.

Signing usually signs a hash of the message, not the whole message. A hash is a short fingerprint: change one character and the fingerprint changes completely, so verification also proves the message was not altered.

What is the difference between a public key and a private key?

The public key is for sharing and for locking things up; the private key is for keeping and for unlocking things and signing. They have opposite jobs, and swapping them breaks the system.

PropertyPublic keyPrivate key
Who can see itAnyoneOnly its owner
Used to encryptYesNo
Used to decryptNoYes
Used to signNoYes
Used to verify a signatureYesNo
If it leaksNo direct harmFull compromise: revoke and replace it

A common mistake is to treat the public key as an identity on its own. It is not. A public key by itself does not prove who owns it. That proof comes from a certificate, a trusted directory, or a check you already made, such as comparing a fingerprint over a channel you trust.

Another mistake is to share a private key by email or chat to make setup easier. Do not do that. Once a private key has travelled over an insecure channel, assume it is compromised and generate a new pair.

How is public-key cryptography different from symmetric encryption?

Symmetric encryption uses one shared secret key for both encryption and decryption, while public-key cryptography uses a pair of different keys. Symmetric ciphers are fast; public-key ciphers solve the problem of sharing the secret in the first place.

In practice, systems combine them. This is called hybrid encryption. Public-key cryptography securely exchanges a short symmetric session key, and then a fast symmetric cipher such as AES encrypts the actual data. You get the convenience of public keys and the speed of symmetric encryption. The TLS 1.3 specification, RFC 8446, describes how that handshake works in detail.

That combination is exactly what happens in TLS, the protocol behind HTTPS. The handshake uses public-key cryptography to authenticate the server and agree on session keys, then symmetric encryption protects the traffic that follows. RFC 8446, which defines TLS 1.3, describes authentication through asymmetric cryptography such as RSA or ECDSA.

Symmetric keys also have a scaling problem. With 100 people, every pair needs its own shared secret. With public keys, each person needs only one pair, and anyone can reach them using their public key.

Which algorithms use public-key cryptography?

The main algorithms are RSA, elliptic-curve cryptography, Diffie-Hellman key exchange and the newer post-quantum algorithms. Each rests on a different hard math problem, and each suits different jobs.

  • RSA: based on the difficulty of factoring the product of two large prime numbers. Widely used for encryption and signatures, and still common in certificates and TLS.
  • Elliptic-curve cryptography (ECC): based on the elliptic-curve discrete logarithm problem. It gives similar security to RSA with much shorter keys, which suits phones and small devices.
  • Diffie-Hellman: lets two parties agree on a shared secret over a public channel, without either side sending the secret itself. Elliptic-curve Diffie-Hellman is the modern form used in TLS.
  • Digital Signature Algorithm (DSA) and ECDSA: signature-only algorithms, used to sign data so others can verify it.
  • Post-quantum algorithms: ML-KEM for key encapsulation and ML-DSA for signatures, standardized by NIST in 2024 to resist future quantum computers.

Key size is not a detail to guess at. NIST's key-management guidance, SP 800-57 Part 1 Rev. 5, covers the protection each key type needs and the key-management functions involved. As a practical rule, use RSA keys of at least 2,048 bits, and prefer 3,072 bits for data that must stay secret for a long time.

How do digital signatures work?

A digital signature proves who signed a message and that the message has not changed since. The signer hashes the message and encrypts that hash with their private key; anyone can verify it with the public key.

Verification has two outcomes, and both matter. If the signature checks out, you know the holder of the private key signed that exact content. If it does not, either the content changed or the signature is not from that key holder, and you should not trust it.

Signatures are everywhere once you look. Software updates are signed so your device can reject a tampered package. Email authentication uses DKIM signatures so a receiving server can check that a message really came from your domain and was not altered. Our guide to what DKIM is explains that email case in detail.

A signature is not the same as encryption. A signed message can still be readable by anyone. If you need both secrecy and proof of origin, you encrypt and sign, in the order your protocol requires.

Where is public-key cryptography used every day?

You use it every day in TLS, email, software updates, passkeys and messaging. Most of the time it is invisible, which is a sign that the protocol designers did their job.

Where you meet public-key cryptography every dayWebsites (TLS)HTTPS, certificates,server authenticationEmailDKIM signatures,encrypted mailSoftware updatessigned packages,rejected if tamperedPasskeys and loginsyour device signs a challenge; no password travelsMessagingend-to-end encryption keys exchanged per contact
Everyday uses of public-key cryptography, from TLS to passkeys. Illustration by Cysoro.

When you visit a secure site, your browser checks the server's certificate, uses the server's public key in the TLS handshake, and agrees on session keys. You can check a site's certificate and TLS setup yourself with our free SSL checker.

Passkeys are a newer use worth knowing. Your device holds a private key and the service holds only the public key. When you sign in, your device signs a challenge from the service. There is no password to steal, and a fake site cannot reuse the signature for the real one.

Secure messaging apps use public keys to set up end-to-end encryption between contacts. Each person's public key is exchanged, often verified by scanning a code or comparing a safety number, and then messages are encrypted so only the intended recipient can read them.

What is public-key infrastructure (PKI)?

Public-key infrastructure is the system of certificates, authorities and rules that makes public keys trustworthy at scale. Without it, you would have no reliable way to know whose public key you are using.

The main parts are certificate authorities that issue and revoke certificates, registration processes that check an applicant's identity, certificate stores in browsers and operating systems, and revocation lists that record certificates that should no longer be trusted.

PKI is also where most real-world failures happen. A certificate issued to the wrong party, a private key left in a public code repository, or an expired certificate can each break trust even when the underlying math is sound. That is why certificate monitoring matters: an expired certificate takes a site offline just as surely as a server outage.

For a small business, the practical PKI checklist is short: use certificates from a trusted authority, automate renewal, keep private keys in a secure store with limited access, and watch expiry dates. Our certificate monitoring page explains how automated expiry alerts fit into that routine.

What can go wrong with public-key cryptography?

The math rarely fails first. Keys are lost, stolen, misused or replaced, and those human and operational failures cause most real incidents.

  • Private key theft: malware, a leaked backup or a key committed to a public repository gives an attacker your identity.
  • Weak or short keys: old 1,024-bit RSA keys no longer provide enough security. Use current recommended sizes.
  • Fake certificates: an attacker who can get a certificate for your domain, or trick you into trusting their key, can impersonate you.
  • Poor randomness: keys generated with weak random numbers can be guessed or reproduced.
  • Quantum computers: a sufficiently powerful quantum computer could break RSA and ECC. NIST finalized three post-quantum standards in August 2024, and administrators are encouraged to start planning the transition now.
  • Expired certificates: a lapsed certificate breaks TLS and erodes trust, even though nothing was attacked.
Never share a private keyDo not email, chat or paste a private key to make setup faster. If a private key has been shared or exposed, revoke its certificate, generate a new key pair, and replace every credential that depended on it.

How should you use public-key cryptography safely?

Use it through trusted tools, protect private keys, and keep keys and certificates current. You do not need to do the math yourself, but you do need good key hygiene.

  1. Use recommended key sizes and algorithms. Prefer modern defaults in your tools, and follow NIST key-management guidance rather than picking sizes by habit.
  2. Store private keys securely. Use a hardware security key, a password manager, or your operating system's secure key store. Limit who and what can access them.
  3. Back up keys safely. An encrypted backup in a separate location protects you from loss, but an unencrypted backup is a leak waiting to happen.
  4. Automate certificate renewal. Short-lived certificates are safer, but only if renewal is automatic.
  5. Verify keys when identity matters. Compare certificate details and fingerprints before trusting a new key for a sensitive exchange.
  6. Plan for post-quantum migration. Inventory where RSA and ECC are used, and follow NIST's post-quantum standards as vendors add support. NIST's August 2024 announcement names ML-KEM, ML-DSA and SLH-DSA as the first finalized standards.
  7. Keep software updated. Crypto libraries are patched when flaws are found. Old libraries can undermine even a good key.

If you run a website, start with the basics: a valid certificate, TLS 1.2 or 1.3, and strong security headers. Check your setup with the security headers checker and the SSL checker linked above.

The bottom line

Public-key cryptography lets strangers talk in private and lets you prove a message is really yours, all without sharing a secret first. The public key locks and verifies; the private key unlocks and signs.

Your job is not the math. It is the hygiene around it: protect private keys, use trusted certificates, use current key sizes, and plan for the post-quantum shift NIST has already started. Get those right and the cryptography does the rest. You can test your own site's TLS setup in seconds with the free SSL checker.

Frequently asked questions

How does public-key cryptography work in simple terms?

You generate two linked keys. You share the public key with everyone and keep the private key secret. Anyone can lock a message with your public key, but only your private key can unlock it. For signatures the roles reverse: you sign with your private key and anyone can check the signature with your public key.

What is the difference between a public key and a private key?

The public key is designed to be shared openly and is used to encrypt data or verify a signature. The private key is kept secret by its owner and is used to decrypt data or create a signature. The two are mathematically linked, but deriving the private key from the public key is computationally infeasible at safe key sizes.

Is public-key cryptography the same as asymmetric encryption?

Yes, the terms are used interchangeably. Asymmetric means the two sides use different keys, unlike symmetric encryption, where both sides share one secret key. Public-key cryptography also covers digital signatures and key agreement, which are not encryption in the usual sense.

Can someone work out my private key from my public key?

Not with current computers at recommended key sizes. The security rests on hard math problems, such as factoring large numbers for RSA or the elliptic-curve discrete logarithm problem. That is why key size matters, and why NIST finalized new post-quantum standards in August 2024 for a future with quantum computers.

Why is public-key cryptography slow?

The math behind it is heavy compared with symmetric ciphers such as AES. In practice, systems use public-key cryptography for a short job, such as exchanging a symmetric session key or signing a hash, and then use fast symmetric encryption for the bulk of the data.

What is public-key cryptography used for?

It secures websites through TLS, encrypts email, signs software updates and documents, authenticates servers and users, and lets two strangers agree on a shared secret key. It also underpins certificates, passkeys and secure messaging.

What happens if my private key is stolen?

Anyone with it can decrypt messages sent to you and impersonate you by signing as you. Treat a suspected compromise as urgent: revoke the affected certificate, generate a new key pair, and reissue anything that depended on the old key.

Do I need to understand the math to use public-key cryptography?

No. Most people use it through tools and protocols that handle the math, such as a browser, a password manager or an email client. What matters is the practice: protect private keys, use trusted certificates, keep software updated, and use recommended key sizes.

Sources

  1. NIST CSRC — Public key cryptography (PKC) glossary
  2. NIST — NIST Releases First 3 Finalized Post-Quantum Encryption Standards
  3. IETF — RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3
  4. NIST — SP 800-57 Part 1 Rev. 5, Recommendation for Key Management: Part 1 – General
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against the NIST CSRC glossary definition of public-key cryptography, NIST SP 800-57 Part 1 Rev. 5, RFC 8446 (TLS 1.3) and NIST's post-quantum standards announcement.

How we write and fact-check →

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free