RSA Algorithm in Cryptography: Working, Encryption, Security, and Applications
By Rahul Singh
Updated on Jul 03, 2026 | 11 min read | 3.29K+ views
Share:
All courses
Certifications
More
By Rahul Singh
Updated on Jul 03, 2026 | 11 min read | 3.29K+ views
Share:
Table of Contents
TL;DR
In this blog you will understand what is RSA algorithm in Cryptography, how RSA key generation works, how encryption and decryption happen step by step, and where this algorithm fits in modern security systems. We will also cover a RSA algorithm example with real numbers and a simple RSA algorithm in C approach.
From learning core algorithms to building intelligent applications, upGrad's Data Science courses help you develop practical skills in Python, machine learning, data engineering, and AI with real-world projects.
Popular Data Science Programs
The RSA Algorithm is an asymmetric encryption algorithm used to protect sensitive information over untrusted networks. Unlike symmetric encryption, where the same key encrypts and decrypts data, RSA uses two different keys:
The public key encrypts data or verifies digital signatures, while the private key decrypts data or creates digital signatures. This separation allows secure communication without sharing secret keys.
Today, the RSA algorithm in cryptography is widely used for secure web browsing, online banking, digital certificates, VPN authentication, email encryption, and software signing.
Also Read: Difference Between Symmetric and Asymmetric Cryptography: Key Features and Uses
RSA stands for Rivest, Shamir and Adleman, the three scientists who created it in 1977. The RSA algorithm is one of the earliest and most widely used public key cryptography systems in the world. It allows two people to exchange information securely even if they have never met or shared a secret key before.
The RSA Algorithm belongs to a category called public key cryptography. Instead of one key, two keys work together.
Imagine Rohan wants to send a secure message to Sumit.
The process looks like this:
Even if someone intercepts the encrypted message, they cannot read it without Sumit's private key.
This makes public key cryptography much safer for communication across the internet.
Also Read: What is End-to-End Encryption? How It Works, and Why We Need It
Even with newer algorithms available, RSA is still active in browsers, banking systems, government platforms and email tools. It remains important because:
This long track record is exactly why so many people still search for what is RSA algorithm and how the RSA algorithm in cryptography fits into today's security stack.
This section breaks down the actual working of the RSA algorithm step by step, so even if you are new to cryptography, you can follow along.
The RSA algorithm follows a straightforward architecture:
This flow is what makes RSA encryption algorithm reliable for secure communication over open networks like the internet. It also shows how the RSA algorithm in cryptography stays consistent no matter what kind of data is being protected.
Also Read: Cryptography in Blockchain: Top Types and Algorithms You Must Know!
Every RSA key pair has two parts:
Here, n is a large number formed by multiplying two prime numbers, and e and d are mathematically connected values used for locking and unlocking data.
Also Read: Computer Networking Basics: Key Concepts, Types, and Benefits Explained
RSA key generation follows a fixed set of steps. The process includes these key steps along with RSA algorithm formula:
Select two large prime numbers.
p = 61
q = 53
Multiply both primes.
n = p × q
n = 61 × 53 = 3233
The value of n becomes part of both keys.
φ(n) = (p − 1)(q − 1)
= 60 × 52
= 3120
Choose an integer e that satisfies:
A common value is:
e = 17
Find d such that:
d × e ≡ 1 mod φ(n)
The calculated value becomes:
d = 2753
Now the keys are:
Key |
Value |
| Public Key | (17, 3233) |
| Private Key | (2753, 3233) |
Suppose Rohan wants to send the number:
65
Using Sumit's public key:
Ciphertext = Mᵉ mod n
Substituting the values:
65¹⁷ mod 3233
= 2790
The encrypted message becomes:
2790
Even if someone intercepts 2790, they cannot recover 65 without Sumit's private key.
Also Read: Comprehensive Guide to Network Commands: Importance, Types, and Best Practices
Sumit receives:
2790
Using his private key:
Message = Cᵈ mod n
Substituting:
2790²⁷⁵³ mod 3233
= 65
The original message is restored.
This process demonstrates how the RSA algorithm example works in practice.
If you are learning to build this yourself, writing the RSA algorithm in C is a common beginner exercise, since C makes the modular arithmetic and prime number handling easy to see step by step.
The following C program demonstrates the basic RSA workflow by generating keys, encrypting a numeric message, and decrypting it to recover the original value.
#include <stdio.h>
long long modPow(long long base, long long exp, long long mod) {
long long result = 1;
base %= mod;
while (exp > 0) {
if (exp % 2 == 1)
result = (result * base) % mod;
exp /= 2;
base = (base * base) % mod;
}
return result;
}
int main() {
// Public Key (e, n)
long long e = 17;
long long n = 3233;
// Private Key (d, n)
long long d = 2753;
// Original message
long long message = 65;
// Encryption
long long cipher = modPow(message, e, n);
// Decryption
long long decrypted = modPow(cipher, d, n);
printf("Original Message : %lld\n", message);
printf("Encrypted Message: %lld\n", cipher);
printf("Decrypted Message: %lld\n", decrypted);
return 0;
}
Output
Operation |
Result |
| Original Message | 65 |
| Encrypted Message | 2790 |
| Decrypted Message | 65 |
This example demonstrates the core RSA workflow. It uses the public key (17, 3233) to encrypt the message and the private key (2753, 3233) to decrypt it. While the values are intentionally small for learning purposes, production systems use key sizes of 2048 bits or higher to provide strong security.
Also Read: Introduction to Cyber Security: A Complete Beginner’s Guide
Data Science Courses to upskill
Explore Data Science Courses for Career Progression
Beyond encryption, the RSA algorithm plays a major role in verifying identity and integrity through digital signatures.
A digital signature is a mathematical proof that a message came from a specific sender and was not altered along the way. It works almost like a handwritten signature, but far harder to forge, because it is tied to the sender's private key.
To sign a message with RSA:
Since only the sender holds the private key, nobody else can generate this exact signature.
To verify the signature:
If even one character in the message changes, the hash values will not match, and the signature fails.
Also Read: Cyber Security Threats: What are they and How to Avoid
Digital signatures are one of the biggest reasons RSA is still trusted in banking, legal documents and software distribution today.
Strengthen your foundation in algorithms, AI, and data-driven technologies with upGrad's M.Sc. in Artificial Intelligence and Data Science. Build practical skills in machine learning, deep learning, Python, and data engineering through hands-on projects designed for real-world applications.
Security is the whole point of RSA, so it is worth understanding exactly where its strength comes from.
Key Size |
Security Level |
Common Use |
| 1024-bit | Weak, outdated | Legacy systems only |
| 2048-bit | Strong, current standard | Most websites and apps |
| 3072-bit | Very strong | High-security systems |
| 4096-bit | Maximum practical strength | Long-term sensitive data |
Most modern platforms now use at least 2048-bit keys as the baseline for the RSA algorithm.
Also Read: SHA-256 Algorithm in Cryptography: Key Features, Applications and More
Suppose two prime numbers are multiplied together.
Finding the product is easy.
Finding the original prime numbers from that product becomes extremely difficult when the numbers contain hundreds of digits.
For example:
61 × 53 = 3233
Factoring 3233 is simple.
Factoring a 2048-bit RSA modulus would take an impractical amount of computing power using current methods.
This mathematical challenge is the foundation of RSA algorithm in cryptography.
Yes, RSA remains secure when implemented correctly.
Modern security recommendations include:
Although quantum computing may affect RSA in the future, it continues to secure millions of websites and enterprise systems today.
Also Read: The Role of Cryptography in Cybersecurity: Importance, Types, and Applications
No system is completely risk-free, and RSA has known weak points if it is implemented poorly.
Attackers attempt every possible private key.
Prevention
Attackers try to recover the prime numbers used during key generation.
Prevention
Instead of attacking the mathematics, attackers observe timing, power consumption, or hardware behavior.
Prevention
Also Read: Top 30 Cyber Security Project Topics in 2026
Poor random number generators may produce predictable primes.
Prevention
Incorrect padding schemes can expose encrypted data.
Prevention
Attackers intentionally introduce hardware errors during cryptographic operations.
Prevention
If attackers obtain the private key, RSA security is lost.
Prevention
Also Read: Top 15 Cybersecurity Analyst Skills for Success in 2026
Subscribe to upGrad's Newsletter
Join thousands of learners who receive useful tips
Like any technology, the RSA algorithm has clear strengths and real limitations.
RSA is not the right pick when you need to encrypt large volumes of data quickly, or when performance on low-power devices is a priority. In those cases, symmetric algorithms usually perform better.
Advantage |
Limitation |
Recommendation |
| Strong security with public/private keys | Slower for large data | Use RSA for key exchange, not bulk data |
| No shared secret needed | Larger keys needed over time | Move to 2048-bit or higher now |
| Supports digital signatures | Vulnerable to future quantum attacks | Monitor post-quantum cryptography updates |
Also Read: What is Quantum AI?
People often compare the RSA algorithm with other encryption methods to decide what fits their project.
RSA and AES solve different security problems.
RSA is an asymmetric algorithm that uses two keys, while AES is a symmetric algorithm that uses one shared secret key.
Feature |
RSA |
AES |
| Encryption Type | Asymmetric | Symmetric |
| Keys | Public and Private | Shared Secret Key |
| Speed | Slower | Very Fast |
| Best For | Key exchange, digital signatures | Encrypting files and data |
| Typical Key Size | 2048–4096 bits | 128, 192, 256 bits |
Which should you choose?
Elliptic Curve Cryptography (ECC) provides similar security using much smaller keys.
Feature |
RSA |
ECC |
| Security | High | High |
| Key Size | Larger | Smaller |
| Performance | Slower | Faster |
| Resource Usage | Higher | Lower |
| Best For | Enterprise systems | Mobile and IoT devices |
Although both are used in secure communication, they serve different purposes.
Feature |
RSA |
Diffie-Hellman |
| Main Purpose | Encryption and Digital Signatures | Secure Key Exchange |
| Encryption | Yes | No |
| Digital Signatures | Yes | No |
| Authentication | Yes | Requires additional mechanisms |
| Common Usage | SSL/TLS, Certificates | VPNs, Secure Sessions |
Diffie-Hellman establishes a shared secret key, while RSA can both encrypt data and verify identities.
Feature |
RSA |
AES |
ECC |
Diffie-Hellman |
| Encryption Type | Asymmetric | Symmetric | Asymmetric | Key Exchange |
| Speed | Slow | Very Fast | Fast | Fast |
| Digital Signatures | Yes | No | Yes | No |
| Key Exchange | Yes | No | Yes | Yes |
| Large Data Encryption | No | Yes | Limited | No |
| Typical Use | Certificates, Authentication | Data Encryption | Mobile Security | Secure Session Setup |
Also Read: 5 Essential Data Science Topics Every Beginner Should Learn
The RSA algorithm is not just a classroom topic, it runs quietly behind many systems you use every day.
Industry |
RSA Usage |
Purpose |
| Banking | Secure transactions, authentication | Protect financial data |
| E-commerce | SSL/TLS certificates | Secure checkout and payments |
| Healthcare | Encrypted patient records | Maintain data privacy |
| Government | Digital signatures on documents | Verify authenticity |
| Software industry | Code signing certificates | Confirm software integrity |
The RSA algorithm remains one of the most important building blocks of digital security today. From securing your online banking session to verifying a software update, this public key cryptography system quietly protects data across the internet every single day.
Understanding what is RSA algorithm, how RSA key generation works, and where it fits alongside AES, ECC and Diffie-Hellman gives you a much clearer picture of modern cryptography as a whole. Whether you are a student trying an RSA algorithm example for the first time, or a developer implementing RSA algorithm in C, the core ideas stay the same, two keys, one math problem that is easy to create and extremely hard to reverse.
Want personalized guidance on Data Science and upskilling? Speak with an expert for a free 1:1 counselling session today.
The RSA Algorithm is an asymmetric encryption algorithm that uses a public key for encryption and a private key for decryption. It is widely used for secure communication, digital signatures, and authentication.
RSA generates a public and private key pair using large prime numbers. Data is encrypted with the public key and decrypted with the private key, ensuring only the intended recipient can read the message.
Public key cryptography uses two mathematically related keys instead of one shared secret. The public key can be shared openly, while the private key remains confidential, making secure communication possible over public networks.
RSA keys are generated by selecting two large prime numbers, calculating their product, finding Euler's Totient Function, and generating public and private exponents that satisfy specific mathematical conditions.
RSA encryption converts plaintext into ciphertext using the recipient's public key and modular arithmetic. Only the matching private key can decrypt the ciphertext back into its original form.
RSA creates a digital signature by encrypting a message hash with the sender's private key. The receiver verifies the signature using the sender's public key to confirm authenticity and message integrity.
RSA security relies on the computational difficulty of factoring very large numbers into their original prime factors. With properly generated 2048-bit or larger keys, breaking RSA remains impractical using current computing methods.
Poor implementations, weak keys, or compromised private keys can weaken RSA. Proper key generation, secure padding, and recommended key sizes make successful attacks extremely difficult with today's technology.
Neither is universally better. RSA is designed for secure key exchange and digital signatures, while AES is much faster for encrypting large amounts of data. Most secure systems use both together.
RSA is used in HTTPS websites, SSL/TLS certificates, online banking, VPNs, secure email, software code signing, cloud authentication, and government security systems to protect sensitive information.
Yes. RSA remains secure when using modern implementations with at least 2048-bit keys, secure padding schemes, and proper key management. It continues to protect millions of secure internet connections worldwide.
95 articles published
Rahul Singh is an Associate Content Writer at upGrad, with a strong interest in Data Science, Machine Learning, and Artificial Intelligence. He combines technical development skills with data-driven s...
Speak with Data Science Expert
By submitting, I accept the T&C and
Privacy Policy
Start Your Career in Data Science Today
Top Resources