RSA: how it works
Key generation, encryption, decryption and signing with RSA, explained step by step without complicated formulas.
RSA can be described in three moments: creating the keys, using the public key and using the private key.
- 01
Choose two prime numbers
Two very large primes are generated at random, each over three hundred decimal digits long for a 2048-bit key.
- 02
Compute the modulus
The two primes are multiplied: the product, called the modulus, is part of both keys.
- 03
Choose the public exponent
A number with certain properties relative to the primes is chosen; in practice almost always 65537.
- 04
Compute the private exponent
Knowing the two primes, a second number is calculated: the private exponent. Without knowing them, calculating it is infeasible.
- 05
Publish the public key
Modulus and public exponent are distributed; the primes are destroyed or kept with the private key.
Encrypting and signing
| Operation | Key used | Who can do it |
|---|---|---|
| Encrypt a message for Anna | Anna’s public key | Anyone |
| Decrypt the message | Anna’s private key | Only Anna |
| Sign a document | Anna’s private key | Only Anna |
| Verify the signature | Anna’s public key | Anyone |
RSA: history
From Diffie and Hellman’s 1976 revolution to the invention of RSA, from the patent to the discovery of the secret British precedent.
The pages of this topic
Back to the overviewRSA: the maths
The formulas of RSA — modulus, Euler’s function, exponents, encryption and decryption — and the factoring problem on which security rests.
RSA: worked example
A complete RSA example with small numbers, from choosing the primes to encrypting and decrypting a number.
RSA: weaknesses and attacks
Known attacks on RSA: keys that are too short, faulty random numbers, vulnerable padding, timing attacks and the threat of quantum computers.
RSA today
Where RSA is still used — certificates, digital signatures, email and code — and why it is giving way to elliptic curves and post-quantum algorithms.
RSA: pitfalls to avoid
The most common mistakes developers and administrators make with RSA, from short keys to home-made implementations.
RSA: frequently asked questions
Short answers to the most common doubts about RSA, keys, security and quantum computers.