RSA Algorithm in Cryptography: Working, Encryption, Security, and Applications

By Rahul Singh

Updated on Jul 03, 2026 | 11 min read | 3.29K+ views

Share:

TL;DR

  • RSA is a public key encryption algorithm that secures data using public and private keys. 
  • It protects online communication through encryption, digital signatures, and secure key exchange. 
  • RSA security is based on the difficulty of factoring large prime numbers. 
  • It is widely used in SSL/TLS, email encryption, digital certificates, and banking systems. 
  • RSA is commonly paired with AES to deliver both strong security and high performance.

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.

What Is RSA Algorithm?

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:

  • Public Key
  • Private Key

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

What is RSA?

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.

Public Key Cryptography Explained

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:

  1. Sumit creates a public key and a private key.
  2. Sumit shares only the public key.
  3. Rohan encrypts the message using Sumit's public key.
  4. Sumit decrypts the message using his private key.

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

Why RSA Remains Important

Even with newer algorithms available, RSA is still active in browsers, banking systems, government platforms and email tools. It remains important because:

  • It has been tested publicly for over four decades.
  • It supports both encryption and digital signatures.
  • It integrates easily with existing security protocols like SSL/TLS.
  • Its math is well understood, which makes it predictable and trustworthy.
  • The RSA algorithm in cryptography is taught in almost every security course, which keeps it relevant for students and professionals alike.

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.

How Does RSA Algorithm Works

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.

RSA Algorithm Architecture and Workflow

The RSA algorithm follows a straightforward architecture:

  1. A key pair is generated, public and private.
  2. The public key is shared with anyone who wants to send data.
  3. The sender encrypts the message using the public key.
  4. The receiver decrypts it using their private key.

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!

RSA Encryption Workflow

Public and Private Keys

Every RSA key pair has two parts:

  • Public key (e, n): used for encryption, safe to share with anyone.
  • Private key (d, n): used for decryption, must stay secret.

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 Algorithm Key Generation

RSA key generation follows a fixed set of steps. The process includes these key steps along with RSA algorithm formula:

Step 1: Choose Two Prime Numbers 

Select two large prime numbers.

p = 61
q = 53

Step 2: Calculate n

Multiply both primes.

n = p × q
n = 61 × 53 = 3233

The value of n becomes part of both keys.

Step 3: Calculate Euler's Totient

φ(n) = (p − 1)(q − 1)
= 60 × 52
= 3120

Step 4: Choose the Public Exponent

Choose an integer e that satisfies:

  • 1 < e < φ(n)
  • gcd(e, φ(n)) = 1

A common value is:

e = 17

Step 5: Calculate the Private Exponent

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)

RSA Algorithm Encryption Process

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

RSA Algorithm Decryption Process

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.

RSA Algorithm in C

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

background

Liverpool John Moores University

MS in Data Science

Double Credentials

Master's Degree18 Months

Placement Assistance

Certification6 Months

RSA Algorithm Digital Signatures

Beyond encryption, the RSA algorithm plays a major role in verifying identity and integrity through digital signatures.

What Is a Digital Signature?

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.

Signing a Message

To sign a message with RSA:

  1. Create a hash (short fixed-length summary) of the message.
  2. Encrypt that hash using the sender's private key.
  3. Attach this encrypted hash to the original message as the signature.

Since only the sender holds the private key, nobody else can generate this exact signature.

Signature Verification

To verify the signature:

  1. The receiver decrypts the signature using the sender's public key.
  2. The receiver independently hashes the received message.
  3. If both hash values match, the message is verified as authentic and unaltered.

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

Benefits of RSA Digital Signatures

  • Confirms the true sender of a message.
  • Detects any tampering during transmission.
  • Provides legal and technical proof of authenticity.
  • Works alongside RSA encryption algorithm for full security, both privacy and identity verification.

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.

Why Is the RSA Algorithm Secure?

Security is the whole point of RSA, so it is worth understanding exactly where its strength comes from.

Security Features

  • Uses two mathematically linked but functionally separate keys.
  • Private key is never transmitted or exposed.
  • Security scales with key size, larger keys mean stronger protection.
  • Backed by decades of public cryptographic review.

Recommended RSA Key Sizes

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

Why Factorization Is Difficult

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.

Is RSA Still Secure?

Yes, RSA remains secure when implemented correctly.

Modern security recommendations include:

  • Use at least 2048-bit keys.
  • Generate random prime numbers.
  • Apply secure padding such as OAEP.
  • Protect private keys with hardware security modules.
  • Rotate compromised keys immediately.

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

Common Attacks on RSA Algorithm and How to Prevent Them

No system is completely risk-free, and RSA has known weak points if it is implemented poorly.

1. Brute-Force Attacks

Attackers attempt every possible private key.

Prevention

  • Use 2048-bit or larger keys.
  • Replace outdated keys.

2. Factorization Attacks

Attackers try to recover the prime numbers used during key generation.

Prevention

  • Generate sufficiently large random primes.
  • Avoid predictable values.

3. Side-Channel Attacks

Instead of attacking the mathematics, attackers observe timing, power consumption, or hardware behavior.

Prevention

  • Use constant-time implementations.
  • Protect cryptographic hardware.

Also Read: Top 30 Cyber Security Project Topics in 2026

4. Weak Prime Numbers

Poor random number generators may produce predictable primes.

Prevention

  • Use cryptographically secure random number generators.
  • Generate unique primes for every key pair.

5. Padding Attacks

Incorrect padding schemes can expose encrypted data.

Prevention

  • Use OAEP for encryption.
  • Use PSS for digital signatures.

6. Fault Attacks

Attackers intentionally introduce hardware errors during cryptographic operations.

Prevention

  • Validate computations.
  • Use secure hardware modules.

7. Lost or Compromised Keys

If attackers obtain the private key, RSA security is lost.

Prevention

  • Store keys securely.
  • Rotate compromised keys immediately.
  • Use Hardware Security Modules (HSMs).

Best Practices for Securing RSA

  • Use 2048-bit keys or higher.
  • Apply proper padding schemes.
  • Store private keys securely, never in plain text.
  • Rotate and retire old keys regularly.
  • Combine RSA with other protocols for layered security.

Also Read: Top 15 Cybersecurity Analyst Skills for Success in 2026

Subscribe to upGrad's Newsletter

Join thousands of learners who receive useful tips

Promise we won't spam!

Advantages and Limitations of the RSA Algorithm

Like any technology, the RSA algorithm has clear strengths and real limitations.

Advantages

  • Strong, well-tested security model.
  • Supports both encryption and digital signatures.
  • No need to share secret keys in advance.
  • Widely supported across almost every platform and language.

Limitations

  • Slower than symmetric algorithms like AES for large data.
  • Requires larger key sizes as computing power grows.
  • Not ideal for encrypting large files directly.
  • Vulnerable to future quantum computing attacks.

When RSA Is Not The Best Choice

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?

RSA vs Other Cryptographic Algorithms

People often compare the RSA algorithm with other encryption methods to decide what fits their project.

RSA vs AES

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?

  • Choose RSA for secure key exchange and authentication.
  • Choose AES for encrypting large amounts of data.
  • Modern systems often use RSA to exchange an AES key, then AES encrypts the actual data.

RSA vs ECC

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

RSA vs Diffie Hellman

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.

Which Encryption Algorithm Should You Choose?

  • Choose AES for encrypting large files or data at rest.
  • Choose RSA for secure key exchange and digital signatures.
  • Choose ECC when you need strong security with smaller keys, especially on mobile or IoT devices.
  • Choose Diffie-Hellman when the main goal is a secure key agreement between two parties.

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

Applications of the RSA Algorithm

The RSA algorithm is not just a classroom topic, it runs quietly behind many systems you use every day.

 

RSA Algorithm Real World Applications

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

Conclusion

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.   

Frequently Asked Question (FAQs)

1. What is the RSA Algorithm?

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.

2. How does the RSA Algorithm work?

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.

3. What is public key cryptography?

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.

4. How are RSA keys generated?

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.

5. How does RSA encryption work?

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.

6. How do RSA digital signatures work?

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.

7. Why is RSA considered secure?

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.

8. Can the RSA Algorithm be broken?

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.

9. RSA vs AES: Which is better?

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.

10. Where is RSA used in real life?

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.

11. Is the RSA Algorithm still secure today?

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.

Rahul Singh

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

+91

By submitting, I accept the T&C and
Privacy Policy

Start Your Career in Data Science Today

Top Resources

Recommended Programs

IIIT Bangalore logo

The International Institute of Information Technology, Bangalore

Executive Diploma in DS & AI

360° Career Support

Executive Diploma

12 Months

Liverpool John Moores University Logo
bestseller

Liverpool John Moores University

MS in Data Science

Double Credentials

Master's Degree

18 Months

upGrad Logo

Certification

3 Months