Network security

RSA Encryption: How Public-Key Encryption Works, Key Sizes and Uses

RSA is the public-key system behind TLS certificates, digital signatures and secure key exchange. Here is how the maths works, which key size to choose, and what quantum computing changes.

Cysoro Security TeamPublished · 7 min read
n = p × qPUBLIC KEYPRIVATE KEY NETWORK SECURITY RSAencryption One public key locks. One private key opens.
Quick answer

RSA encryption is a public-key cryptosystem in which anyone can encrypt a message with the recipient's public key, but only the holder of the matching private key can decrypt it. Its security rests on the difficulty of factoring a large number that is the product of two secret primes. RSA-2048, the most common size, gives about 112 bits of security and is defined in RFC 8017.

Key takeaways

  • RSA uses a key pair: the public key encrypts and verifies, the private key decrypts and signs.
  • RSA-2048 gives about 112 bits of security; use 3072-bit keys for data that must stay secret past 2030.
  • In practice RSA rarely encrypts data directly — it protects a symmetric key, which then encrypts the data.

Every time you visit a secure website, your browser and the server agree on a secret key without ever sharing one in advance. RSA is the algorithm that makes that possible. It is the public-key system behind TLS certificates, digital signatures and secure logins — and it rests on one simple fact: multiplying two large primes is easy, but pulling the product back apart is not.

What is RSA encryption?

RSA encryption is a public-key cryptosystem in which anyone can encrypt a message with the recipient's public key, but only the holder of the matching private key can decrypt it. It is named for Rivest, Shamir and Adleman, who publicly described it in 1977.

RSA was the first practical public-key cryptosystem. Before it, two parties who had never met had no safe way to agree on a secret key over a public network. RSA solved that key-distribution problem: publish one key, keep the other secret, and nothing secret ever needs to travel.

The standard that defines RSA today is RFC 8017, PKCS #1 version 2.2. It specifies the key format, the encryption schemes and the signature schemes that implementations must follow to work together.

How does RSA encryption work?

RSA runs on modular arithmetic and a key pair. The public key is a modulus and a public exponent; the private key is the matching private exponent. What the public key locks, only the private key can unlock.

RSA key generation in five stepsp, qPick two primeslarge, random,kept secretn = p × qModuluspublic; its sizeis the key sizeφ(n)Totient(p − 1) × (q − 1),kept secrete = 65537Public exponentalmost always65537dPrivate exponentinverse of e,kept secretSecurity rests on factoring n back into p and q — easy to multiply, infeasible to reverse.
RSA key generation: two secret primes become one public modulus. Illustration by Cysoro.

Key generation

Choose two large random prime numbers, p and q — each about 1,024 bits for RSA-2048. Compute n = p × q, the modulus. Compute the totient, choose a public exponent e (commonly 65537), and derive the private exponent d as the inverse of e modulo the totient.

The public key is (n, e). The private key is (n, d). Security rests entirely on factoring: if an attacker could factor n back into p and q, they could reconstruct the private key.

Encryption and decryption

To encrypt, raise the message to the public exponent modulo n. To decrypt, raise the ciphertext to the private exponent modulo n. The maths guarantees the original message comes back — but only with the right private key.

A toy example makes the pattern clear: with p = 61 and q = 53, the modulus is n = 3233, the totient is 3120, a public exponent of e = 17 gives a private exponent of d = 2753. Real keys use primes hundreds of digits long, so the same steps are infeasible to reverse.

Why padding matters

Raw, textbook RSA is unsafe: the same message always encrypts to the same ciphertext, and small messages can be attacked directly. Real RSA always uses padding. OAEP is the modern padding scheme for encryption, defined in RFC 8017; the older PKCS #1 v1.5 padding is kept only for compatibility. Never use unpadded RSA.

RSA vs AES: what is the difference?

RSA is asymmetric and AES is symmetric. RSA uses a public and a private key and is slow; AES uses one shared secret key and is fast. They solve different problems, so real systems use both.

RSAAES
Key typeAsymmetric — public + private key pairSymmetric — one shared secret key
SpeedSlow, especially decryptionVery fast, hardware-accelerated
Key distributionNo secret needs to be shared in advanceBoth sides must share the secret key
Data sizeSmall — at most about 214 bytes with OAEP for RSA-2048Unlimited, in blocks
Main jobsKey exchange, digital signatures, certificatesBulk encryption of data and traffic
Typical sizes2048 or 3072 bits128, 192 or 256 bits

The hybrid pattern is everywhere: RSA (or elliptic-curve key exchange) protects a randomly generated AES session key, and AES encrypts the actual data. TLS works this way, as does most encrypted messaging and file encryption. You can check the result on any site with our free SSL checker.

What RSA key size should you use?

Key size is the length of the modulus in bits. Bigger is stronger against classical computers, but slower — and the security gained is much smaller than the number suggests. RSA-2048 does not give 2,048 bits of security.

Key sizeSecurity strengthMax data with OAEPStatus
RSA-1024About 80 bitsAbout 86 bytesBroken — never use; an 829-bit RSA key was factored in 2020
RSA-2048About 112 bitsAbout 214 bytesCurrent standard; accepted today
RSA-3072About 128 bitsAbout 342 bytesRecommended for long-lived data
RSA-4096About 140 bitsAbout 470 bytesStrongest common size; slower

NIST SP 800-57 Part 1 rates RSA-2048 at about 112 bits of security, roughly comparable to a 112-bit symmetric key and well below AES-256. NIST's post-quantum transition plan schedules 112-bit RSA for deprecation after 2030, so choose 3072-bit keys — or a post-quantum scheme — for data that must stay secret past then. The MojoAuth RSA-2048 guide sets out the same 112-bit figure and the post-2030 deprecation plan.

For a TLS certificate, 2048 bits is still the common default and is accepted by browsers and certificate authorities. For a root certificate or a signing key that must last a decade, 3072 or 4096 bits is the safer choice.

Where is RSA used?

RSA is one of the most widely deployed public-key algorithms in the world. You use it every day, usually without noticing.

  • TLS certificates: the certificate your browser checks when you visit an HTTPS site is usually signed with RSA, and RSA key exchange or signatures set up the encrypted session.
  • Digital signatures: software updates, documents and code are signed with a private key so anyone can verify them with the public key. A signature proves authenticity and integrity; it does not hide the message.
  • SSH keys: many server logins use RSA key pairs instead of passwords.
  • Email signing: DKIM, the email authentication standard, can use RSA signatures to prove a message came from the claimed domain. See our guide to what DKIM is.
  • Key exchange and wrapping: RSA encrypts a symmetric key so it can travel safely over an open network.
Hybrid encryption: RSA + AES together1. Generate a randomAES session key2. Encrypt the AES keywith the RSA public key3. Encrypt the datawith AES, fastOnly the RSA private key can recover the AES key — and only AES touches the bulk data.This is how TLS, encrypted email and most secure file transfer work.
Hybrid encryption: RSA handles the key, AES handles the data. Illustration by Cysoro.

How do RSA digital signatures work?

A digital signature is RSA run in reverse. The sender hashes the message, then encrypts that hash with their private key. Anyone can decrypt the hash with the sender's public key and compare it with a fresh hash of the message.

If the two hashes match, the message was not changed and only the private-key holder could have signed it. That gives authenticity and integrity. It does not give confidentiality: the message itself is still readable, only the signature is secret-key protected.

This is why a certificate is trustworthy. A certificate authority signs a website's public key with its own private key, and your browser verifies that signature against a public key it already trusts. Break the chain, and the browser warns you.

Can quantum computers break RSA?

Yes, in theory — and that is RSA's single point of failure. A large enough quantum computer running Shor's algorithm could factor the modulus and recover the private key, at every key size. Bigger keys buy a little time against classical computers, but Shor's cost grows only polynomially with key size, so enlarging the key does not save RSA.

NIST finalized post-quantum replacements in August 2024: ML-KEM for key establishment, and ML-DSA and SLH-DSA for signatures. The practical advice is to inventory where RSA is used, prefer hybrid or crypto-agile designs for new systems, and move long-lived secrets to 3072-bit keys or post-quantum algorithms first. The Lamarr Labs RSA field guide explains the same quantum risk and the standardized replacements.

For now, RSA-2048 remains secure against classical computers: no one has publicly factored a 2048-bit RSA modulus. The risk is not today, but a future machine decrypting data captured today — the reason long-lived data needs the stronger choice now.

What mistakes should you avoid with RSA?

Most RSA failures are implementation mistakes, not maths failures. The algorithm is sound; the way people use it often is not.

  • Using a key that is too small. Never use 1024-bit keys, and do not generate keys with a weak random number generator.
  • Skipping padding. Always use OAEP for encryption and PSS for signatures; never use raw RSA.
  • Encrypting large data directly. RSA can only encrypt data smaller than the modulus, so use hybrid encryption instead.
  • Sharing or losing the private key. Anyone with the private key can decrypt and sign as you. Store it encrypted, back it up securely, and revoke the certificate if it leaks.
  • Reusing one key everywhere. Use separate keys for encryption and signing, and for different services.

The bottom line

RSA encryption lets strangers agree on a secret without sharing one in advance, using a public key to lock and a private key to unlock. Its security rests on factoring, its standard is RFC 8017, and RSA-2048 remains the common, accepted size today.

Use 3072-bit keys for data that must outlive 2030, always use OAEP padding, and let RSA protect a symmetric key rather than the data itself. You can see the result in action by checking any site's certificate with the free SSL checker.

Frequently asked questions

What is RSA encryption in simple terms?

RSA is a way to send a secret message to someone you have never met. They publish a public key that anyone can use to lock a message, and they keep a private key that is the only key that can unlock it. No secret needs to be shared in advance.

What does RSA stand for?

RSA stands for Rivest, Shamir and Adleman — Ron Rivest, Adi Shamir and Leonard Adleman, who publicly described the algorithm at MIT in 1977 and published it in 1978. It was the first practical public-key cryptosystem.

How does RSA encryption work?

Key generation picks two large secret primes, multiplies them to make a modulus, and derives a public exponent and a private exponent. Encryption raises the message to the public exponent modulo the modulus; decryption raises the result to the private exponent. Only someone who knows the primes can derive the private exponent.

Is RSA-2048 still secure?

Yes, for now. RSA-2048 gives about 112 bits of security, which NIST currently accepts, and no one has publicly factored a 2048-bit RSA modulus. NIST plans to deprecate 112-bit security after 2030, so use 3072-bit keys for long-lived secrets.

What is the difference between RSA and AES?

RSA is asymmetric: it uses a public and a private key, and it is slow. AES is symmetric: it uses one shared secret key and is fast. In practice, RSA protects the AES key and AES encrypts the data — a hybrid system that gets the strengths of both.

Where is RSA used today?

RSA is used in TLS certificates that secure HTTPS websites, in digital signatures for software and documents, in SSH keys, in email signing, and in key exchange that sets up encrypted sessions. It is one of the most widely deployed public-key algorithms in the world.

Can quantum computers break RSA?

Yes, in theory. A large enough quantum computer running Shor's algorithm could factor the modulus and recover the private key at any key size. That is why NIST finalized post-quantum algorithms in August 2024, including ML-KEM for key establishment and ML-DSA for signatures.

Should I use RSA or elliptic curve cryptography?

Elliptic curve cryptography gives the same security with much smaller keys and faster operations, so it is often the better choice for new systems. RSA remains the safer default when you need broad compatibility, for example with older systems and certificate authorities.

Sources

  1. MojoAuth — RSA 2048 Encryption in R: Keys and Examples
  2. CryptKit — RSA-2048 Encryption: The Complete Guide
  3. Lamarr Labs Field Guide — RSA
  4. Insper — RSA and Ed25519
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 RFC 8017 (PKCS #1 v2.2) as described in the RSA guides cited, and NIST SP 800-57 Part 1 key-size guidance as summarized in those guides.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

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

Start free