By Bonaventure Ogeto · Published · Last verified:
Public-Key Cryptography Explained: How Diffie-Hellman and RSA Changed Everything
The short answer
Public-key cryptography uses a pair of keys: a public key anyone can use to encrypt or check a signature, and a private key only its owner holds. Diffie-Hellman (1976[1]) let strangers agree a secret in public and RSA (1977[2]) made encryption and signatures practical, which is why every secure website depends on public-key cryptography.
Source: Mctaba Labs, “Public-Key Cryptography Explained: How Diffie-Hellman and RSA Changed Everything”, last verified 4 December 2026, mctaba.com/learn/cryptography/public-key-cryptography-explained
What problem does public-key cryptography solve?
For most of history every cipher was symmetric: the same secret key encrypted and decrypted the message. That works if you can meet the other person first, or send the key by trusted courier. It fails on a network full of strangers. You cannot send the key over the network itself, because anyone listening would copy it.
This is the key distribution problem. An IEEE history of the period says that until public-key cryptography arrived, secure communication was believed impossible without first exchanging a secret key, with key distribution a major impediment[3].
Public-key cryptography, also called asymmetric cryptography, removes the need to share a secret in advance. Each person has two mathematically linked keys. The public key can be published to the world. The private key never leaves its owner. What one key does, only the other can undo or check. The wider comparison with symmetric ciphers, hashing and signatures is in symmetric vs asymmetric encryption, hashing and digital signatures.
How do public and private keys work?
Think of a padlock. Suppose you hand out open padlocks to anyone who asks. They can snap one shut on a box and send it to you, but only you hold the key that opens it. The open padlock is your public key; the key on your keyring is your private key. A thief who copies the padlock gains nothing, because a padlock can only close the box. That is public-key encryption.
Digital signatures run the other way round. Picture a rubber stamp only you own, whose print anyone can compare with a sample you have published. You sign a document with your private key, and anyone can check the signature with your public key, but nobody else can produce it. Change even one letter of the signed document and the check fails.
In real systems the keys are very large numbers, and the security rests on a maths problem that is easy in one direction and hard in the other. Diffie and Hellman put the requirement plainly: computing the decryption key from the encryption key must be computationally infeasible[1].
How does Diffie-Hellman key exchange work?
In November 1976[1] Whitfield Diffie and Martin Hellman published New Directions in Cryptography, whose first line placed the field “on the brink of a revolution in cryptography”[1]. The paper proposed two ideas: public key cryptosystems, and public key distribution systems that remove the need for a secure channel to share keys. The second became Diffie-Hellman key exchange.
The classic way to picture it is with paint. Amina and Brian agree in public on a common colour, say yellow. Each secretly picks a private colour, mixes it into some yellow, and they swap the mixtures in the open. Each then adds their own private colour to the mixture they received. Both end up with the same final colour. An eavesdropper who saw the yellow and both mixtures cannot unmix the paint to get there.
In the real protocol the colours are numbers and the mixing is modular arithmetic, a kind of clock arithmetic where numbers wrap around after a fixed value. Mixing is fast; unmixing means solving what mathematicians call the discrete logarithm problem, which has no known efficient method on ordinary computers for well-chosen numbers.
Diffie-Hellman does not encrypt anything by itself. It produces a shared secret, which both sides then use as the key for a fast symmetric cipher. Diffie and Hellman received the 2015 A.M. Turing Award[4], announced in March 2016[4] and often called the “Nobel Prize of computing”[4].
How does RSA encryption work?
At MIT in 1977[2], Ron Rivest, Adi Shamir and Leonard Adleman turned the first idea into a working system. Their paper, A Method for Obtaining Digital Signatures and Public-Key Cryptosystems, was received by the journal on 4 April 1977[5] and published in Communications of the ACM in February 1978[6]. It presented an encryption method with the property that “publicly revealing an encryption key does not thereby reveal the corresponding decryption key”[6].
Here is the idea in brief. Pick two large secret prime numbers and multiply them. The product goes into the public key; the primes stay private. To encrypt, the message is treated as a number, raised to a public power and divided by the product, keeping only the remainder. Only someone who knows the two primes can easily reverse that step. The paper says the system's security rests in part on the difficulty of factoring[5] the published product. Multiplying primes is quick; working backwards from a large product to its primes is the hard part, and RSA stays safe only while it stays hard.
RSA does two jobs. It can encrypt a small secret, such as a key for a symmetric cipher, to someone's public key, and it can sign data, which is why the paper's title leads with digital signatures. The trio received the 2002 A.M. Turing Award[7].
A Kenyan example shows RSA at work in payments. Safaricom's Daraja documentation, as archived in December 2019[8], told developers to produce the SecurityCredential for certain M-Pesa API calls by encrypting the initiator password with the M-Pesa public key certificate using RSA, then base64-encoding the result. M-Pesa's core system decrypts it with the matching private key to authenticate the transaction.
Did GCHQ invent public-key cryptography first?
Yes, in secret. GCHQ says James Ellis conceived of “non-secret encryption”[9], now called public-key cryptography. Clifford Cocks then devised the system now known as RSA, and Malcolm Williamson shortly afterwards devised a key exchange method now known as Diffie-Hellman, which GCHQ says academic researchers found independently at almost the same time[10].
The dates differ by source. The UK's National Cyber Security Centre puts Ellis's idea in 1970[11]. The IEEE Milestone record says he had shown it was possible by the end of 1969[3], that Cocks joined GCHQ in 1973[3], and that Williamson's method dates from 1974[3].
None of it could be published. The IEEE Milestone says the principles were kept secret until 1997[3], and Cocks was allowed to speak publicly about the work only in December 1997[3]. Ellis died on 25 November 1997[9], about a month before GCHQ's achievement was announced. The open world built its internet on the published papers. The longer story is in the history of cryptography.
What is elliptic curve cryptography?
In 1985[12] Neal Koblitz and Victor Miller both proposed building cryptographic schemes on elliptic curves over finite fields. An elliptic curve here is a set of points defined by a simple equation, with a rule for combining two points to get a third. Repeating that operation is easy; undoing it, known as the elliptic-curve discrete logarithm problem, is believed to be very hard. Miller's paper at CRYPTO '85[13], written at IBM Research, proposed an elliptic-curve version of the Diffie-Hellman key exchange.
Elliptic curves now do much of the everyday work. Cloudflare says the elliptic-curve key exchange X25519 now secures the majority of Internet connections[14], on its own or paired with a post-quantum algorithm. WhatsApp's encryption white paper says each device's long-term identity key is a Curve25519 key pair[15]. Elliptic-curve signature schemes such as ECDSA and EdDSA sign certificates, software updates and transactions.
How do Diffie-Hellman, RSA and elliptic curves compare?
| Diffie-Hellman | RSA | Elliptic curves | |
|---|---|---|---|
| First published | November 1976[1] | February 1978[6] | 1985[12] |
| What it does | Lets two parties agree a shared secret over an open channel | Encrypts small secrets to a public key and creates digital signatures | Key exchange (ECDH, X25519) and signatures (ECDSA, EdDSA) |
| Hard problem underneath | Discrete logarithms | Factoring the product of two large primes | Elliptic-curve discrete logarithms |
| Encrypts your data itself? | No: it produces a key for a symmetric cipher | Only small items such as keys | No: it agrees keys or signs |
| Where you meet it | TLS 1.3 handshakes, as (EC)DHE | Certificates and signatures; the M-Pesa API credential in Safaricom's archived Daraja docs | Most internet key exchanges (X25519); WhatsApp identity keys |
| Against a large quantum computer | Rendered impotent by Shor's algorithm[16] | No longer secure[16] | No longer secure[16] |
Why does the internet depend on public-key cryptography?
Every time a browser or banking app opens a secure connection, public-key cryptography does the first and hardest step. TLS (Transport Layer Security) is the protocol behind HTTPS. Its current version, TLS 1.3, is now specified in RFC 9846, published in July 2026[17], which replaced the original RFC 8446. A TLS 1.3 handshake works like this:
- The client and server each create a fresh, temporary key pair and run a Diffie-Hellman exchange over elliptic curves or finite fields. TLS 1.3 removed static RSA and Diffie-Hellman key exchange, so all public-key based key exchange provides forward secrecy[17].
- The server proves who it is by signing the handshake with the private key behind its certificate, usually an RSA or elliptic-curve key, and the client checks that signature.
- Both sides derive symmetric keys from the shared secret and switch to a fast symmetric cipher such as AES for the data itself.
Forward secrecy means that stealing a server's long-term private key later does not expose recorded past sessions, because each session's key came from temporary keys that were thrown away. It does not help against a future quantum computer, which could solve each recorded exchange directly; that is the harvest now, decrypt later threat. The standard also leaves room for change: it says other extensions define the use of key-encapsulation mechanisms (KEMs)[17], the route post-quantum algorithms take into TLS.
The same pattern, public keys to agree a secret and prove identity, then symmetric encryption for the bulk, protects bank app logins, Daraja API calls and online checkouts. How encryption protects your M-Pesa, bank app and WhatsApp messages walks through those everyday cases.
Will quantum computers break public-key cryptography?
A large enough quantum computer would. Diffie-Hellman, RSA and elliptic curves all rest on factoring or discrete logarithms, and in 1994[16] Peter Shor showed that a quantum computer could solve both efficiently. NIST says that would leave public-key systems built on them impotent[16]. The symmetric step is in far better shape: Google's Chrome team notes that in TLS the symmetric encryption is considered safe against quantum cryptanalysis, but the way the symmetric keys are created is not[18].
No published attack breaks deployed encryption today. No one knows when a machine big enough will exist, and NIST says experts' estimates range from a few years to a few decades[19]. But the timetable is set: NIST will deprecate quantum-vulnerable public-key cryptography after 2030 and disallow it after 2035[20].
The replacements are already arriving. RFC 10024[21], published in August 2026[21], defines hybrid TLS groups such as X25519MLKEM768 that combine elliptic-curve Diffie-Hellman with the post-quantum ML-KEM. NIST describes the aim of hybrids as keys that remain secure if at least one of the component schemes is secure[20]. How Shor's algorithm attacks these systems is covered in how quantum computers could break RSA and elliptic curve encryption, and the new algorithms in what is post-quantum cryptography. The cryptography series hub sets out the whole transition.
Frequently asked questions
- What is the difference between a public key and a private key?
- The public key can be shared with anyone and is used to encrypt messages to you or to check your signatures. The private key stays with you and is used to decrypt those messages or to create signatures. The two are mathematically linked, but working out the private key from the public one is designed to be infeasible.
- Is Diffie-Hellman an encryption algorithm?
- Not on its own. It is a key agreement method: two parties use it to arrive at the same secret number over an open channel, then use that secret as the key for a symmetric cipher such as AES. Diffie and Hellman called it a public key distribution system[1].
- Is RSA still safe to use?
- Against today’s computers, yes: no published method breaks RSA at the key sizes in current use. But it is quantum-vulnerable, and NIST will deprecate it after 2030[20] and disallow it after 2035[20]. New systems should plan their move to post-quantum algorithms now.
- Who invented public-key cryptography?
- James Ellis, Clifford Cocks and Malcolm Williamson at GCHQ worked it out first, but their work stayed secret until 1997[3]. Whitfield Diffie and Martin Hellman published the idea in 1976[1], and Rivest, Shamir and Adleman published RSA in 1978[6].
- Why is public-key cryptography called asymmetric?
- Because the two keys are different: one locks or signs, the other opens or checks. In symmetric cryptography the same key does both jobs. Most real systems use both: public keys to agree a secret and prove identity, then a symmetric cipher to encrypt the data.
- Does WhatsApp use public-key cryptography?
- Yes. WhatsApp’s end-to-end encryption is based on the Signal Protocol, and its encryption white paper says each device has a long-term Curve25519 key pair[15] as its identity key, an elliptic-curve key. The design is meant to stop third parties, and WhatsApp itself, from reading messages.
Sources
- [1] IEEE Transactions on Information Theory (copy on Martin Hellman's Stanford page), November 1976, checked 4 December 2026
- [2] MIT News, 30 April 2003, checked 4 December 2026
- [3] IEEE History Center, Engineering and Technology History Wiki, 5 October 2010, checked 4 December 2026
- [4] Stanford University (CISAC, Freeman Spogli Institute), Stanford News story, 1 March 2016, checked 4 December 2026
- [5] Rivest, Shamir and Adleman (author's copy on Ronald Rivest's MIT page), February 1978, checked 4 December 2026
- [6] Communications of the ACM (scan on Ronald Rivest's MIT page), February 1978, checked 4 December 2026
- [7] Weizmann Institute of Science, 2003, checked 4 December 2026
- [8] Safaricom Daraja developer portal (API Documentation), Internet Archive snapshot of 10 December 2019, 10 December 2019, checked 4 December 2026
- [9] GCHQ, checked 4 December 2026
- [10] GCHQ, checked 4 December 2026
- [11] National Cyber Security Centre (UK), checked 4 December 2026
- [12] Standards for Efficient Cryptography Group (SEC 1 v2.0, Certicom Research), 21 May 2009, checked 4 December 2026
- [13] Springer (Advances in Cryptology, CRYPTO '85 Proceedings), 1986, checked 4 December 2026
- [14] Cloudflare, 28 October 2025, checked 4 December 2026
- [15] WhatsApp (Meta), WhatsApp Encryption Overview technical white paper, 30 October 2026, checked 4 December 2026
- [16] NIST, April 2016, checked 4 December 2026
- [17] RFC Editor (IETF), July 2026, checked 4 December 2026
- [18] Google (Chromium Blog), 10 August 2023, checked 4 December 2026
- [19] NIST, 27 February 2026, checked 4 December 2026
- [20] NIST, October 2026, checked 4 December 2026
- [21] RFC Editor (IETF), August 2026, checked 4 December 2026
Related guides
- The History of Cryptography: Caesar, Enigma and the Birth of Modern Encryption
- What Is Post-Quantum Cryptography? A Plain-English Explanation (2026)
- Symmetric vs Asymmetric Encryption, Hashing and Digital Signatures
- How Quantum Computers Could Break RSA and Elliptic Curve Encryption
- Cryptography explained: the full series
