How Does Public-Key Encryption Keep Online Payments Safe? | How It Works
On this page
What is the short answer?
When the student pays online, the card details cross networks run by strangers. First, the browser and the shop's server must agree on a secret key in plain view. Public-key encryption makes that possible.
A key exchange builds a shared secret in public, and a digital certificate ties the server to the shop's domain name. A fast symmetric cipher then protects the payment. Card networks add their own layers, so stolen data is hard to reuse.
Definition: Public-key encryption uses two linked keys. The public key can be shared with anyone; it locks data or checks a signature. Only the matching private key, which never leaves its owner, can unlock that data or make that signature.
Why is one shared secret key not enough?
Most encryption is symmetric: one key locks and unlocks the data. Ciphers such as AES, which every TLS 1.3 program must support, are fast and strong. Their weakness is the key-distribution problem. Both sides must already hold the key, and sending it over the network would hand it to any eavesdropper.
If every pair among n people needs its own key, the count is n × (n minus 1) ÷ 2. For an illustrative 1,000 people, that is 1,000 × 999 ÷ 2 = 499,500 secret keys, against 1,000 key pairs with public keys.
Public-key arithmetic is far slower, so it only sets up the symmetric key and proves identity.
How do a public key and a private key work as a pair?
A key pair rests on a one-way function: easy to compute but, as far as anyone knows, impractical to undo without a secret.
In RSA, published by Ron Rivest, Adi Shamir and Leonard Adleman in February 1978, the easy step is multiplying two large primes and the hard step is factoring the product. The public key holds the product, n, and a number e. The private key, d, is easy to work out only for someone who knows the two primes. Public web certificates that use RSA need an n of at least 2,048 bits, a number 617 digits long.
Diffie-Hellman key exchange, published by Whitfield Diffie and Martin Hellman in November 1976, raises a number to a power and keeps only the remainder after division. Undoing that step is the discrete logarithm problem.
Britain's signals agency, GCHQ, got there first in secret. James Ellis conceived the idea in 1970, Clifford Cocks an RSA-like method in 1973 and Malcolm Williamson a key exchange soon after; all stayed secret until December 1997.
How do signatures and certificates prove who is on the other end?
A criminal's server could run a perfect key exchange too, so the browser must also confirm who it is talking to.
A digital signature reverses the roles of the keys. The signer transforms a short fingerprint of the message, a hash, with the private key. Anyone can check it with the public key, and changing one character makes the check fail.
A certificate is a signed statement linking a domain name to a public key. A certificate authority (CA) signs it, often through intermediate CAs, forming a chain of trust back to a root certificate built into the browser or operating system.
The padlock shows an encrypted link to a server whose domain a trusted CA vouched for, not an honest shop. In May 2023, Chrome's team wrote that nearly all phishing sites show the lock, and that only 11% of participants in its 2021 study understood the icon, so it planned to replace the lock with a neutral settings icon in Chrome 117.
What happens, step by step, in a TLS 1.3 handshake?
TLS 1.3, the current version of the protocol behind HTTPS, was published as RFC 8446 in August 2018 and revised as RFC 9846 in July 2026. A full handshake takes one round trip.
- ClientHello. The browser sends a random number, its ciphers and a key share: its public Diffie-Hellman value, often on the elliptic curve P-256 or X25519.
- ServerHello. The server picks settings and sends its key share. Each side combines its private value with the other's public one, reaches the same secret and derives keys that encrypt everything after, the certificate included.
- Certificate and CertificateVerify. The server sends its certificate chain and signs the whole handshake with its private key.
- Finished. The server adds a check code, a MAC, over the whole handshake, so any altered message is caught.
- The browser checks. It verifies the chain to a trusted root, the name, dates, signature and code, then sends its own Finished.
- Payment data. Card details now travel under a symmetric cipher such as AES-GCM.
TLS 1.3 dropped sending the session key under the server's long-term RSA key, so all its public-key exchanges give forward secrecy: a private key stolen later cannot unlock recorded past sessions.
What do card payments add on top of the encrypted link?
Beyond TLS, the card industry adds three layers, set out by EMVCo, a technical body owned by six card networks, including Visa and Mastercard.
- Tokenisation. The card number is swapped for a payment token that can be limited to one merchant, device or kind of payment, so a token stolen from one shop can fail at any other. The Reserve Bank of India, for example, began enforcing card-on-file tokens on 1 October 2022, leaving only card networks and issuers to store real card numbers.
- Chip cryptograms. EMVCo counts more than 15.6 billion chip cards in use. For each payment, the chip computes a one-time cryptogram from details such as the amount and date, with a key derived from the issuer's master key. The issuer recomputes it; an old code cannot be reused. This step uses a shared secret, not a key pair.
- 3-D Secure. Online, the shop sends the card issuer data about the payment and device. Low-risk payments pass silently; riskier ones need a one-time passcode or a biometric check. European Union rules applying from 14 September 2019 require strong customer authentication for online payments, with exemptions such as some low-risk ones: two or more of something the payer knows, has or is, with the code tied to the amount and payee.
Where has the chain of trust failed?
In both cases below, the mathematics held; a company and a piece of code failed.
- DigiNotar, the Netherlands, 2011. An attacker took over this Dutch certificate authority and on 10 July 2011 issued a fake certificate valid for any address ending in .google.com. Status checks surged from 4 August; about 300,000 unique internet addresses made them, over 99% in Iran, where investigators said the aim was to intercept private communications. It was revoked on 29 August, and DigiNotar was declared bankrupt on 20 September 2011.
- Heartbleed, 2014. A missing bounds check in OpenSSL, a popular TLS library, let attackers read up to 64 kilobytes of server memory per request, which could hold private keys. Shipped in version 1.0.1 on 14 March 2012, it was disclosed and fixed on 7 April 2014. In Canada, an intruder used it to take about 900 taxpayers' Social Insurance Numbers from the Canada Revenue Agency.
A later safeguard, Certificate Transparency, first specified in June 2013, logs issued certificates publicly so domain owners can spot fakes.
Why are quantum computers forcing new algorithms?
In November 1994, Peter Shor showed that a large quantum computer could factor numbers and find discrete logarithms efficiently. That would break RSA and Diffie-Hellman, elliptic-curve forms included, all listed as vulnerable by the UK's National Cyber Security Centre.
NIST says such machines may be years or decades away. But traffic recorded now could be decrypted then, which Chrome's team calls a store-now-decrypt-later attack. On 13 August 2024, NIST, the United States standards agency, published three replacements:
- FIPS 203, ML-KEM, from CRYSTALS-Kyber, for setting up shared keys.
- FIPS 204, ML-DSA, from CRYSTALS-Dilithium, for digital signatures.
- FIPS 205, SLH-DSA, from SPHINCS+, a backup signature method built on hash functions.
From Chrome 124 in 2024, desktop Chrome began pairing its X25519 key share with a post-quantum Kyber one. Under its final transition plan, NIST IR 8547 of October 2026, NIST will drop quantum-vulnerable algorithms from its standards by 2035.
How does this work with real numbers?
Both examples use tiny, illustrative numbers chosen for this page; real keys are hundreds of digits long. Here, mod n means the remainder after dividing by n.
How does a toy RSA key encrypt and sign?
- Make the keys. Take the primes 41 and 71, so n = 41 × 71 = 2,911 and (41 minus 1) × (71 minus 1) = 2,800. Choose e = 3, which shares no factor with 2,800. Then d = 1,867, since 3 × 1,867 = 5,601 leaves 1 after dividing by 2,800. Public key: 2,911 and 3. Private key: 1,867.
- Encrypt. To lock the message 100: 100 × 100 × 100 = 1,000,000 = 343 × 2,911 + 1,527, so it becomes 1,527.
- Decrypt. 1,527 to the power 1,867, mod 2,911, gives back 100, as a short program confirms.
- Sign and check. Signing a toy hash of 500 gives 500 to the power 1,867, mod 2,911: 1,355. Anyone checks it with e = 3: 1,355 × 1,355 leaves 2,095 mod 2,911, and 2,095 × 1,355 leaves 500. It matches.
Factoring 2,911 rebuilds d, and trying primes in order finds 41 on the thirteenth try. For a 617-digit n, no known method on ordinary computers is practical.
How do two machines agree on a secret in public?
Both sides publicly agree on the prime 29 and base 2.
- The browser keeps 9 secret and sends 2 to the power 9, mod 29: 512 = 17 × 29 + 19, so 19.
- The server keeps 13 secret and sends 2 to the power 13, mod 29: 8,192 = 282 × 29 + 14, so 14.
- The browser computes 14 to the power 9, mod 29, and the server 19 to the power 13, mod 29. Both get 3, since each has computed 2 to the power 9 × 13.
An eavesdropper sees 29, 2, 19 and 14 but needs 9 or 13, a discrete logarithm. Here 28 guesses at most find it, but with X25519's 32-byte secrets no known method is practical.
Where can the student go deeper in World 101?
This page follows one payment from the browser to the card issuer. The World 101 subject Cryptography and Digital Security covers the wider field, from the hardness assumptions behind modern codes to the privacy and legal questions they raise and the careers they offer.
Three related subjects go further. Prime Numbers explains primes as the building blocks of every whole number above 1, and why their properties underpin RSA. Quantum Computing shows how qubits could one day break today's public-key methods, and why hardware problems keep that day distant. Cybersecurity covers how systems are protected from misuse and restored when defences fail, as they did at DigiNotar.
Sources
- W. Diffie and M. Hellman, "New Directions in Cryptography", IEEE Transactions on Information Theory, November 1976.
- R. L. Rivest, A. Shamir and L. Adleman, "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems", Communications of the ACM, February 1978.
- NCSC, "Our history" (Ellis 1970, Cocks 1973), and GCHQ profiles of James Ellis and Malcolm Williamson, read 7 November 2026; IEEE Milestone, dedicated 5 October 2010 (secret until December 1997).
- RFC 8446 (August 2018) and RFC 9846 (July 2026), TLS 1.3; RFC 7748, X25519, January 2016; RFC 6962, Certificate Transparency, June 2013.
- CA/Browser Forum, Baseline Requirements 2.3.1, 4 October 2026: the 2,048-bit RSA minimum.
- Chromium Blog, "An Update on the Lock Icon", 2 May 2023 (2021 study).
- EMVCo pages on itself, tokenisation, 3-D Secure and chip cards, and AWS Payment Cryptography on ARQC cryptograms, read 7 November 2026.
- Reserve Bank of India, press release, 24 June 2022; Statement on Developmental and Regulatory Policies, October 2023.
- Commission Delegated Regulation (EU) 2018/389, applying from 14 September 2019.
- Fox-IT, "Operation Black Tulip", interim report, 5 September 2011; VASCO press release, 4 October 2011.
- OpenSSL advisory CVE-2014-0160, 7 April 2014; heartbleed.com, read 7 November 2026 (release of 14 March 2012).
- Office of the Privacy Commissioner of Canada, statement, 14 April 2014, and annual report 2014-15.
- P. W. Shor, "Algorithms for Quantum Computation: Discrete Logarithms and Factoring", FOCS, Santa Fe, November 1994.
- NIST, FIPS 203 to 205, 13 August 2024; NIST IR 8547 (final) and Post-Quantum Cryptography project, both 27 October 2026 (2035 target).
- UK NCSC, "Next steps in preparing for post-quantum cryptography", 14 August 2024; Google, Chrome post-quantum post, 23 May 2024.
Common errors and misconceptions
- Misconception: The padlock means a shop is safe to buy from. Correct: It shows only an encrypted link to a domain a trusted CA vouched for; nearly all phishing sites show it too.
- Misconception: A stolen server key exposes all its past traffic. Correct: TLS 1.3 key exchanges use fresh Diffie-Hellman values, so a later theft of the certificate key does not unlock recorded sessions.
- Misconception: Quantum computers can already break online payments. Correct: NIST says such machines may be years or decades away; the worry is traffic recorded now.
Key takeaways
- Symmetric ciphers are fast but need a shared key; public-key methods let two strangers agree on one in public.
- In a TLS 1.3 handshake, Diffie-Hellman builds the session key, while a certificate and a signature prove the server's identity.
- Card payments add tokens, one-time chip cryptograms and 3-D Secure checks, so stolen payment data is hard to reuse.
- The DigiNotar hack of 2011 and the Heartbleed bug of 2014 were failures of a company and of code, not of the mathematics.
- Shor's algorithm threatens RSA and Diffie-Hellman, so NIST published the post-quantum standards FIPS 203 to 205 in August 2024.
Test yourself
Why not just send a symmetric key over the internet?
Anyone watching the network could copy it and read everything it protects: the key-distribution problem.
How can anyone check the toy RSA signature 1,355?
With the public key alone: 1,355 to the power 3, mod 2,911, gives 500, the signed hash.
What must an eavesdropper solve to find the toy shared secret 3?
It sees only 29, 2, 19 and 14 and needs a secret exponent, a discrete logarithm, which is impractical at real key sizes.
Why can an old chip cryptogram not be replayed?
Each is a one-time code made from that payment's details with a key in the chip, so an old one fails the issuer's check.
Go deeper in World 101: Cryptography & Digital Security
Write about it
Turn a question from this chapter into a paper.
The Writing Studio has a structure guide, a rubric and citation tools for 15 formats, from essays to research papers. A free account keeps up to five drafts. Learnacy Essential adds feedback from an AI writing coach and submission to The OYI Review.
Publication depends on review and is not guaranteed.
