RSA Encryption: Asymmetric Cryptography for Data Authenticity and Integrity
The RSA encryption method is a form of asymmetric cryptography, also called public-key cryptography, that uses a pair of mathematically linked keys so that encrypted data can only be read by the intended recipient.
It’s a reliable method for securing data transfers, but it limits the amount of data you can transfer and is computationally heavy. As a result, it’s usually used to protect the exchange of faster symmetric keys or confirm the identity of the data sender.
This guide explains what RSA encryption is, the mathematics it relies on, how the encryption and decryption process works, and how it holds up against modern cybersecurity threats.
Table of Contents
What Is RSA Encryption?How Does RSA Encryption Work?
Where Is RSA Encryption Used?
RSA Security Risks and Limitations
RSA Compared to Other Popular Types of Encryption
FAQ
What Is RSA Encryption?
As a public-key cryptosystem, RSA asymmetric encryption secures data using two mathematically linked keys: a public key and a private key. The sender shares the public key and anyone can use it. On the other hand, the sender never shares the private key.
RSA encryption pairs the two keys so that data processed with one key can only be reversed with the other. This allows the system to work bidirectionally, which lets people communicate securely without ever having to share their private keys.
For example, a sender can encrypt data with a recipient’s public key so that only the intended recipient can decrypt it using their private key. The owner of a private key can also use it to encrypt a message and prove that the communication came from them.
The whole system relies on a mathematical algorithm built on the integer factorization problem. This is the art of finding the prime factors of a composite number (i.e., finding factors that can only be divided by themselves and one to produce a whole number – like three, five, seven, and so on, but with much larger numbers).
The calculation is quick to run in one direction but difficult to reverse. That imbalance is what keeps RSA-encrypted data secure. It’s much more time-consuming and resource-intensive to use a public key to work out the private key.
Three researchers at the Massachusetts Institute of Technology: Ron Rivest, Adi Shamir, and Leonard Adleman developed the method in 1977. The “RSA” comes from the initial letters of their surnames.1
The researchers were looking for a practical way to solve a long-standing problem in cryptography: how can two people communicate privately without first meeting to agree on a shared secret key.
Symmetric vs. Asymmetric Encryption
The RSA system uses asymmetric encryption to secure and exchange data, while many other commonly-used ciphers (e.g., AES) use symmetric encryption. Understanding the difference between these two types of encryption can make it easier to follow how RSA encryption works.
Symmetric encryption uses a single shared key for both encrypting and decrypting data. The sender and recipient must both hold an identical copy of the key because it turns readable data into ciphertext and back to readable data.
This setup is fast and efficient, but comes with significant limitations. Sending the shared key to the recipient can potentially allow an attacker to intercept and read every message that’s encrypted with it. Equally, if not more importantly, it doesn’t work in a scenario where you want to limit a user to either encryption or decryption privileges only.
Asymmetric encryption solves these problems by using a linked key pair instead of one key. You can share the public key while the private key stays secret, so there’s no need to distribute it. The trade-off is speed since asymmetric methods are slower and more computationally demanding.
Here’s a side-by-side comparison:
| Feature | Symmetric Encryption | Asymmetric Encryption |
| Keys | One shared key for both encryption and decryption | A linked public and private key pair |
| Key distribution | The sender and recipient securely share the secret key beforehand | The sender shares the public key while the private key stays secret |
| Speed | Fast and efficient, even for large files | Slower and more computationally demanding |
| Best for | Encrypting large amounts of data | Key exchange, digital signatures, and identity verification |
The Math Behind RSA Encryption
The security of the RSA encryption algorithm comes from two mathematical concepts: Large prime numbers and modular arithmetic.
RSA encryption multiplies two large prime numbers to produce a much larger number called the modulus. In a modern 2048-bit RSA key, that modulus can run to roughly 600 digits when written out in full.
We use modular arithmetic, a system where numbers “wrap around” after reaching a set value, to generate the public and private key values. This might sound a bit complicated, but you already use it every time you read a 12-hour analog clock.
Looking at a clock face, you’ll see that once the clock passes 12, it wraps back around to 1. If the time is 10:00 a.m. and you add five hours, the result is 3:00 p.m. because the count starts again after it reaches 12.
Modular arithmetic extends this theory to work with any number. The modulus is the “reset point.” When a number goes past that value, you divide by the modulus and keep only the remainder.
Let’s consider a simple example. In a system with a modulus of 3, the number 5 becomes 2 because 3 goes into 5 once with 2 left over. The number 7 would become 1, because 3 fits into 7 twice with 1 left over.
The first operation – multiplying two primes – is quick to do, but working out which two primes produced the modulus (i.e., factoring) is currently impractical even for powerful computers.
For a sense of scale, researchers factored a 250-digit number known as RSA-250 in 2020, but only after the equivalent of about 2,700 years of processing time spread across many machines working in parallel.2
That number is smaller than the roughly 600-digit modulus used in a standard 2048-bit key, so this would make it challenging to derive the private key from the public key.
RSA Key Sizes
Key size in RSA refers to the length of the modulus, measured in bits. Longer keys are harder to break but slower to use, so the choice is a balance between security and performance.
In the early 2000s, 1024-bit keys were common but they’re now considered obsolete. They provide only around 80 bits of security, which measures how difficult it is to break a cryptographic system. Certificate authorities stopped issuing 1024-bit certificates in 2013. A well-resourced attacker could realistically factor a key of this size.
Today, 2048-bit keys are the baseline. The National Institute of Standards and Technology (NIST) treats 2048-bit RSA as acceptable through 2030, after which it recommends moving to 3072-bit and 4096-bit keys.3
How Does RSA Encryption Work?
The RSA method solves the key distribution problem: how to communicate securely without first sharing a key. To do this, the algorithm follows a defined set of steps for RSA encryption and decryption.

Step 1: Key Generation
Key generation puts the math behind RSA encryption into practice. It produces the public and private keys as a set of numbers, through the following steps:
- Choosing prime numbers: The key generation selects two large prime numbers (p and q) at random and keeps it secret.
- Calculating the modulus: The system multiplies the two primes to produce the modulus (n) which forms part of both keys.
- Finding the totient (linking value): The primes calculate (p – 1) × (q – 1), a value that ties the two exponents together.
- Choosing the public exponent: The system chooses a number (e) that shares no factor with the linking value other than 1 and isn’t small enough to create a vulnerability to attacks based on Coppersmith’s small-root method.4
- Deriving the private exponent: The private exponent (d) is calculated from e and the linking value, so that the two exponents reverse each other.
The owner can share the public key pair (n, e). The private key pair (n, d) must stay secret.
RSA Encryption Key Generation Example
Here’s an RSA encryption calculation example that uses small prime numbers to make the mechanics a little easier to understand. We’ll start with how to work out the public key:
- p = 3
- q = 11
- n = (p × q) = (3 × 11) = 33
The two prime numbers also produce a second value that links the exponents, with the equation (p – 1) × (q – 1). The public exponent (e) can be any number below this value that only shares 1 as a factor. In our case:
- (p – 1) × (q – 1) = (3 – 1) × (11 – 1) = 20
Here, 7 can work as the public exponent as it doesn’t share a factor with 20, so:
- e = 7
Let’s move on to the private exponent (d). This is the number that, when multiplied by e leaves a remainder of 1 after being divided by the result of (p – 1) × (q – 1):
- d = 3
Here, 3 works because 7 × 3 = 21, and 21 leaves a remainder of 1 when divided by 20.
This means that the public key is (33, 7) and the private key is (33, 3).
Step 2: Key Distribution
With the keys generated, the owner can publish or send the public key to anyone who wants to communicate in a secure manner. It can appear in a directory, attached to an email, or embedded in a website’s security certificate.
The public key has two uses: encrypting data that only the key owner can decrypt and reversing data that the key owner has processed with their private key. Because you can’t use the public key to work out the private key, sharing it creates no risk.
The private key is different. The owner should never share or transmit it, so it’s usually stored in a protected location on the owner’s device or server. Anyone who obtains the private key can decrypt every message meant for the owner and can also impersonate them.
Most real-world security failures involving RSA are not from breaking the math, but from attackers exposing or stealing private keys, or organizations protecting them poorly.
Step 3: Encryption
Encryption applies the public key to a message using modular arithmetic. The message is first converted into numbers and padded with extra data to strengthen security. This number is then raised to the power of the public exponent e – 7 in our example above – and then reduced to (mod n).
Written out, the calculation is c = me(mod n), where m is the message and c is the resulting ciphertext. Using the public key (33, 7) from our earlier example, the message m = 5 encrypts to 5^7(mod 33), which equals 14. So the ciphertext is 14.
Anyone with the public key can run this calculation, but the result can only be turned back into the original message with the matching private key.
The same calculation can also run in reverse, with the private key applied to the message and the matching public key used to undo it.
This offers no privacy, because the public key is available to everyone and anyone can reverse the result. What it provides instead is proof of origin, as only the holder of the private key could have produced output that its public key correctly reverses. Digital signatures work this way.
Step 4: Decryption
Decryption reverses the encryption process using the private key. The recipient raises the ciphertext to the power of the private exponent (d) and then reduces the result modulo n. Written out, the calculation is m = cd(mod n).
Using the private key (33, 3) from our earlier example, the ciphertext 14 decrypts to 14^3 (mod 33). This gives us 5, which is the original message.
The two prime numbers mathematically link the public and private exponents, so a message encrypted with one key can only be decrypted with the other.
An attacker who sees both the ciphertext and the public key still can’t recover the message, because that would require them to factor the modulus back into its original primes – a process that’s impractical with the large prime numbers.
Where Is RSA Encryption Used?
Because RSA can only encrypt data smaller than its key size, it’s not well-suited to transferring large files or continuous data streams. It’s often used to verify identity or to protect the smaller symmetric keys that do the heavy lifting of bulk encryption.
The most common RSA encryption applications include:
- SSL/TLS certificates: The Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols use RSA to secure web browsing over HTTPS, confirming that a website is genuine and helping set up the encrypted connection between browser and server.
- SSH key pairs: Secure Shell (SSH) uses RSA key pairs to authenticate users connecting to remote servers, replacing password logins with something much harder to guess.
- Digital signatures: RSA confirms that a document, email, or piece of software came from its stated sender and no one altered it in transit.
- PGP and GPG: Pretty Good Privacy (PGP) and its open equivalent, GNU Privacy Guard (GPG), use RSA to protect the keys that encrypt email and file contents.
RSA Security Risks and Limitations
Most weaknesses in RSA encryption come from how it’s implemented rather than the algorithm itself. There’s also a longer-term threat emerging from quantum computing. The main risks worth understanding fall into three categories.
Weak Random Number or Key Generation
The security of RSA depends on choosing prime numbers that are random and unpredictable. If the random number generation is weak, the primes become guessable, which undermines the whole system.
One well-documented problem occurs when two different keys accidentally share a prime factor.5 Factoring a single large modulus is impractical. However, if two keys share a prime, anyone can find it in milliseconds by calculating the greatest common divisor of the two numbers. That single shared prime then exposes both private keys.
Implementation Flaws
Even with strong keys, RSA encryption can be attacked through the way it’s built into software and hardware. These are known as side-channel attacks.
Instead of trying to factor the modulus, an attacker measures physical characteristics of the system as it performs decryption:
- Timing attacks: Records how long operations take as the duration can vary depending on the private key’s values.
- Power analysis: Measures fluctuations in a device’s power consumption during calculations.
- Fault attacks: Deliberately introduces errors (e.g., by disrupting the power supply) and studies the faulty output for clues.
Each of these can gradually leak information about the private key without ever breaking the underlying encryption.
Quantum Computing
The most significant long-term threat to RSA comes from quantum computing. A quantum algorithm can, in principle, factor large numbers far faster than any known method. As a result, a powerful quantum computer running Shor’s algorithm7 could break RSA encryption.
Fortunately, that type of machine doesn’t exist yet. No quantum computer today can factor the numbers used in real RSA keys, so current encryption remains secure for now. The concern is both the future risk and the possibility of harvesting data today to decrypt once the technology matures.
In response, the National Institute of Standards and Technology finalized its first post-quantum encryption standards in 2024.7 One of them, a key-exchange method called ML-KEM, will replace RSA for securing connections and migration toward this standard is already underway.
RSA Compared to Other Popular Types of Encryption
The RSA method is one of several encryption methods available today. It solves the key distribution and identity problems that symmetric methods cannot, but it’s slow and limited in how much data it can handle.
Symmetric ciphers like AES and ChaCha20 are the opposite. They’re fast and efficient for bulk data but not as secure for sharing keys.
In practice, systems often use symmetric and asymmetric encryption together. An asymmetric method like RSA sets up the connection and safely exchanges a symmetric key, while the faster symmetric method then encrypts the bulk of the data.
Here’s a closer look at how they compare:
| Feature | RSA | AES | ChaCha20 |
| Encryption type | Asymmetric | Symmetric | Symmetric |
| Cipher type | Integer-based (operates on numbers) | Block cipher | Stream cipher |
| Commonly used for | Key exchange, digital signatures, certificates | Bulk data encryption, file and disk encryption | Bulk data encryption, mobile and low-power devices |
| Limitations | ❌ Slow for large data ❌ Message size capped by key size ❌ Needs large keys for strong security | ❌ Both sides need the same key ❌ The key must be shared securely ❌ Not suited to digital identity confirmation | ❌ Both sides need the same key ❌ Less hardware acceleration than AES ❌ Not suited to digital signatures |
| Benefits | ✅ Secure key distribution ✅ Enables digital signatures ✅ Widely supported | ✅ Very fast ✅ Strong at small key sizes ✅ Often hardware-accelerated | ✅ Fast in software ✅ Strong on mobile and low-power devices ✅ Resistant to timing attacks |
FAQ
What is the RSA encryption algorithm?
The RSA encryption algorithm lets two parties protect data without sharing a key between the sender and receiver. It uses one public and one private key that work as a pair to keep an exchange secure because the large numbers it relies on are difficult to factor.
Is RSA secure?
Yes. When implemented correctly with a 2048-bit key or larger, many consider RSA secure against current threats. Most failures come from weak key generation or exposed private keys rather than the algorithm itself. PIA uses AES-128-GCM encryption and RSA-4096 handshake to help establish its encrypted VPN connections reliably.
How does RSA encryption and decryption work?
Both operations rely on modular arithmetic. Encryption applies the public key to a message, turning it into unreadable ciphertext. Decryption applies the matching private key, turning that ciphertext back into the original message. Only the holder of the private key can complete the decryption step.
AES vs RSA encryption: What’s the difference?
The difference between RSA and AES comes down to their encryption method. As an asymmetric method, RSA uses a public and private key pair, while AES is symmetric and uses a single shared key. RSA is slower and suited to key exchange and signatures; AES is fast and handles bulk data.
When should RSA encryption be used instead of symmetric encryption?
It’s best to use RSA when you need to exchange keys privately or verify identity without a shared secret, such as setting up a connection or signing a document. For encrypting large amounts of data, faster symmetric methods like AES are the better choice.
References:
- A Method for Obtaining Digital Signatures and Public-Key Cryptosystems – MIT
- New record set for cryptographic challenge – UC San Diego
- Recommendation for Key Management, Part 1: General – U.S. Department of Commerce
- Small solutions to polynomial equations, and low exponent RSA vulnerabilities – IBM
- Mining Your Ps and Qs: Detection of Widespread Weak Keys in Network Devices – Factorable
- Shor’s algorithm – IBM
- NIST Releases First 3 Finalized Post-Quantum Encryption Standards – National Institute of Standards and Technology