SlideShare une entreprise Scribd logo
1  sur  7
RSA 
We sometimes need to hide our confidential data from other users. For that purpose we use 
encryption algorithms to encrypt our data. There are very many encryption algorithms but I am 
describing the Rivest, Shamir, Adleman (RSA) Algorithm. 
RSA is an encryption algorithm. 
Developed in: 1977. 
Developed by: Ron Rivest, Adi Shamir, and Leonard Adleman. 
The RSA algorithm is the most commonly used public key encryption algorithm. 
Public Key Encryption 
It is also known as asymmetric cryptography. 
Two keys are used: Public Key and Private Key. 
Public Key: For encryption. 
Private Key: For decryption, also known as a secret key. 
The preceding diagram show how public key encryption works, 
In the diagram 2 users are shown: 
First: The Sender (who is sending something by the recipient's Public Key) 
Second: The Receiver (who is receiving something from the sender using the private key) 
So in a public key cryptosystem, the sender encrypts the data using the public key of the receiver 
and uses an encryption algorithm that is also decided by the receiver and the receiver sends only the 
encryption algorithm and public key.
But by using the public key, data can only be encrypted but not decrypted, and the data is only 
decrypted by the private key that only the receiver has. So no one can hack our data. 
In simple terms: 
Public Key: Shared with the public that wants to send us data. 
Private Key: Kept secret so that when someone sends us data encrypted by our Public Key, we can 
decrypt the data using the Private Key. 
HOW RSA WORKS 
Both users (sender and receiver) generates a public and private key. 
The following is the procedure for generating a public and private key (see flowchart). 
Generation of Public and Private key in RSA 
The flowcharts above shows how to generate a public and private key using RSA. 
After getting the public and private key the main thing is how to encrypt and decrypt using RSA. 
Encryption and Decryption in RSA
encrypt and decrypt.png 
Example of RSA: Here is an example of RSA encryption and decryption with generation of the 
public and private key. 
Generate public and private key: 
Encryption and Decryption
How to use the RSA Algorithm in a C# Windows Forms application 
1. Open Visual Studio. 
2. Select "File" -> "New" -> "Project..." or press "Ctrl +Shift +N". 
3. Now select "Windows Forms application" from the Visual C# templates. 
4. Now design the Windows Forms form such as follows: 
You need to make:
3 TextBoxes for Plain Text, Encrypted Text and Decrypted Text 
and 2 Buttons. 
Now for the coding part. 
Coding 
1. To use the RSA algorithm in C#, we need to add the following namespace: 
using System.Security.Cryptography; 
2. Now make a function for Encryption. 
static public byte[] Encryption(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding) 
{ 
try 
{ 
byte[] encryptedData; 
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider()) 
{ 
RSA.ImportParameters(RSAKey); 
encryptedData = RSA.Encrypt(Data, DoOAEPPadding); 
} return encryptedData; 
} 
catch (CryptographicException e) 
{ 
Console.WriteLine(e.Message); 
return null; 
} 
} 
3. Now make a function for Decryption 
static public byte[] Decryption(byte[]Data, RSAParameters RSAKey, bool DoOAEPPadding) 
{ 
try 
{ 
byte[] decryptedData; 
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider()) 
{ 
RSA.ImportParameters(RSAKey); 
decryptedData = RSA.Decrypt(Data, DoOAEPPadding); 
} 
return decryptedData; 
} 
catch (CryptographicException e) 
{ 
Console.WriteLine(e.ToString()); 
return null;
} 
} 
4. Now make some variables into the class that are: 
UnicodeEncoding ByteConverter = new UnicodeEncoding(); 
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); 
byte[] plaintext; 
byte[] encryptedtext; 
5. Now handle the Click Event for the Encrypt Button with the following code: 
private void button1_Click(object sender, EventArgs e) 
{ 
plaintext = ByteConverter.GetBytes(txtplain.Text); 
encryptedtext = Encryption(plaintext, RSA.ExportParameters(false), false); 
txtencrypt.Text = ByteConverter.GetString(encryptedtext); 
} 
6. Now handle the Click Event for the Decrypt Button with the following code: 
private void button2_Click(object sender, EventArgs e) 
{ 
byte[] decryptedtex = Decryption(encryptedtext, RSA.ExportParameters(true), false); 
txtdecrypt.Text = ByteConverter.GetString(decryptedtex); 
} 
Results
Plain Text: 
Encrypted Text: 
Decrypted Text:

Contenu connexe

Tendances

Web application security: Threats & Countermeasures
Web application security: Threats & CountermeasuresWeb application security: Threats & Countermeasures
Web application security: Threats & Countermeasures
Aung Thu Rha Hein
 
5169 wireless network_security_amine_k
5169 wireless network_security_amine_k5169 wireless network_security_amine_k
5169 wireless network_security_amine_k
Rama Krishna M
 

Tendances (20)

The MD5 hashing algorithm
The MD5 hashing algorithmThe MD5 hashing algorithm
The MD5 hashing algorithm
 
Hacking Wireless Networks : Null Delhi (November)
Hacking Wireless Networks : Null Delhi (November)Hacking Wireless Networks : Null Delhi (November)
Hacking Wireless Networks : Null Delhi (November)
 
Operating Systems: Computer Security
Operating Systems: Computer SecurityOperating Systems: Computer Security
Operating Systems: Computer Security
 
Packet sniffers
Packet sniffers Packet sniffers
Packet sniffers
 
Ceh V5 Module 07 Sniffers
Ceh V5 Module 07 SniffersCeh V5 Module 07 Sniffers
Ceh V5 Module 07 Sniffers
 
Cloud Foundry Networking with VMware NSX
Cloud Foundry Networking with VMware NSXCloud Foundry Networking with VMware NSX
Cloud Foundry Networking with VMware NSX
 
Web application security: Threats & Countermeasures
Web application security: Threats & CountermeasuresWeb application security: Threats & Countermeasures
Web application security: Threats & Countermeasures
 
The SHA Hashing Algorithm
The SHA Hashing AlgorithmThe SHA Hashing Algorithm
The SHA Hashing Algorithm
 
Aircrack
AircrackAircrack
Aircrack
 
5169 wireless network_security_amine_k
5169 wireless network_security_amine_k5169 wireless network_security_amine_k
5169 wireless network_security_amine_k
 
Snort IDS
Snort IDSSnort IDS
Snort IDS
 
Understanding NMAP
Understanding NMAPUnderstanding NMAP
Understanding NMAP
 
Introduction to Cloud Security
Introduction to Cloud SecurityIntroduction to Cloud Security
Introduction to Cloud Security
 
Audio steganography - LSB
Audio steganography - LSBAudio steganography - LSB
Audio steganography - LSB
 
High Availability Asterisk and FreePBX on Microsoft Azure
High Availability Asterisk and FreePBX on Microsoft AzureHigh Availability Asterisk and FreePBX on Microsoft Azure
High Availability Asterisk and FreePBX on Microsoft Azure
 
Nmap basics
Nmap basicsNmap basics
Nmap basics
 
Network scanning
Network scanningNetwork scanning
Network scanning
 
B.tech Final year Cryptography Project
B.tech Final year Cryptography ProjectB.tech Final year Cryptography Project
B.tech Final year Cryptography Project
 
Design patterns through refactoring
Design patterns through refactoringDesign patterns through refactoring
Design patterns through refactoring
 
Effective Java - Generics
Effective Java - GenericsEffective Java - Generics
Effective Java - Generics
 

En vedette

Internet security protocol
Internet security protocolInternet security protocol
Internet security protocol
Mousmi Pawar
 
Operating systems linux
Operating systems linuxOperating systems linux
Operating systems linux
william_morg
 
8 Authentication Security Protocols
8 Authentication Security Protocols8 Authentication Security Protocols
8 Authentication Security Protocols
guestfbf635
 
Digital signatures
Digital signaturesDigital signatures
Digital signatures
Ishwar Dayal
 
Presentation1 linux os
Presentation1 linux osPresentation1 linux os
Presentation1 linux os
joycoronado
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
mcganesh
 
Cipher techniques
Cipher techniquesCipher techniques
Cipher techniques
Mohd Arif
 
Introduction to Linux OS
Introduction to Linux OSIntroduction to Linux OS
Introduction to Linux OS
Mohammed Safwat
 

En vedette (20)

Linux Mint System Components and Environmental Subsystems
Linux Mint System Components and Environmental SubsystemsLinux Mint System Components and Environmental Subsystems
Linux Mint System Components and Environmental Subsystems
 
Block Cipher
Block CipherBlock Cipher
Block Cipher
 
An Introduction To Linux
An Introduction To LinuxAn Introduction To Linux
An Introduction To Linux
 
Block cipher modes of operation
Block cipher modes of operation Block cipher modes of operation
Block cipher modes of operation
 
Internet security protocol
Internet security protocolInternet security protocol
Internet security protocol
 
Tcp header/IP Header/Authentication header
Tcp header/IP Header/Authentication headerTcp header/IP Header/Authentication header
Tcp header/IP Header/Authentication header
 
Operating systems linux
Operating systems linuxOperating systems linux
Operating systems linux
 
8 Authentication Security Protocols
8 Authentication Security Protocols8 Authentication Security Protocols
8 Authentication Security Protocols
 
Chapter 3: Block Ciphers and the Data Encryption Standard
Chapter 3: Block Ciphers and the Data Encryption StandardChapter 3: Block Ciphers and the Data Encryption Standard
Chapter 3: Block Ciphers and the Data Encryption Standard
 
block ciphers
block ciphersblock ciphers
block ciphers
 
Ipsec
IpsecIpsec
Ipsec
 
Linux kernel architecture
Linux kernel architectureLinux kernel architecture
Linux kernel architecture
 
Linux Introduction
Linux IntroductionLinux Introduction
Linux Introduction
 
Digital signatures
Digital signaturesDigital signatures
Digital signatures
 
Presentation1 linux os
Presentation1 linux osPresentation1 linux os
Presentation1 linux os
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Cipher techniques
Cipher techniquesCipher techniques
Cipher techniques
 
Rsa Algorithm
Rsa AlgorithmRsa Algorithm
Rsa Algorithm
 
Linux introduction
Linux introductionLinux introduction
Linux introduction
 
Introduction to Linux OS
Introduction to Linux OSIntroduction to Linux OS
Introduction to Linux OS
 

Similaire à RSA alogrithm

Cryptography and network security
Cryptography and network securityCryptography and network security
Cryptography and network security
patisa
 

Similaire à RSA alogrithm (20)

CRYPTOGRAPHY (2).pdf
CRYPTOGRAPHY (2).pdfCRYPTOGRAPHY (2).pdf
CRYPTOGRAPHY (2).pdf
 
(Crypto) DES And RSA Algorithms Overview
(Crypto) DES And RSA Algorithms Overview(Crypto) DES And RSA Algorithms Overview
(Crypto) DES And RSA Algorithms Overview
 
Rivest Shamir Adleman Algorithm and its variant : DRSA.pptx
Rivest Shamir Adleman Algorithm and its variant : DRSA.pptxRivest Shamir Adleman Algorithm and its variant : DRSA.pptx
Rivest Shamir Adleman Algorithm and its variant : DRSA.pptx
 
Unit-III_3R-CRYPTO_2021-22_VSM.pptx
Unit-III_3R-CRYPTO_2021-22_VSM.pptxUnit-III_3R-CRYPTO_2021-22_VSM.pptx
Unit-III_3R-CRYPTO_2021-22_VSM.pptx
 
Cryptography and network security
Cryptography and network securityCryptography and network security
Cryptography and network security
 
Web cryptography javascript
Web cryptography javascriptWeb cryptography javascript
Web cryptography javascript
 
3 public key cryptography
3 public key cryptography3 public key cryptography
3 public key cryptography
 
Cryptography & Security
Cryptography & SecurityCryptography & Security
Cryptography & Security
 
Rsa Crptosystem
Rsa CrptosystemRsa Crptosystem
Rsa Crptosystem
 
How does cryptography work? by Jeroen Ooms
How does cryptography work?  by Jeroen OomsHow does cryptography work?  by Jeroen Ooms
How does cryptography work? by Jeroen Ooms
 
RSA Algorithem and information about rsa
RSA Algorithem and information about rsaRSA Algorithem and information about rsa
RSA Algorithem and information about rsa
 
RSA Algorithm report
RSA Algorithm reportRSA Algorithm report
RSA Algorithm report
 
Principles of public key cryptography and its Uses
Principles of  public key cryptography and its UsesPrinciples of  public key cryptography and its Uses
Principles of public key cryptography and its Uses
 
IRJET- Data Transmission using RSA Algorithm
IRJET-  	  Data Transmission using RSA AlgorithmIRJET-  	  Data Transmission using RSA Algorithm
IRJET- Data Transmission using RSA Algorithm
 
Information and data security public key cryptography and rsa
Information and data security public key cryptography and rsaInformation and data security public key cryptography and rsa
Information and data security public key cryptography and rsa
 
Cryptography based chat system
Cryptography based chat systemCryptography based chat system
Cryptography based chat system
 
Introduction to Public Key Cryptography
Introduction to Public Key CryptographyIntroduction to Public Key Cryptography
Introduction to Public Key Cryptography
 
Cryptography
CryptographyCryptography
Cryptography
 
Image and text Encryption using RSA algorithm in java
Image and text Encryption using RSA algorithm in java  Image and text Encryption using RSA algorithm in java
Image and text Encryption using RSA algorithm in java
 
F010243136
F010243136F010243136
F010243136
 

Plus de Senthil Kanth

Wireless Communication and Networking by WilliamStallings Chap2
Wireless Communication and Networking  by WilliamStallings Chap2Wireless Communication and Networking  by WilliamStallings Chap2
Wireless Communication and Networking by WilliamStallings Chap2
Senthil Kanth
 

Plus de Senthil Kanth (20)

Wireless Communication and Networking by WilliamStallings Chap2
Wireless Communication and Networking  by WilliamStallings Chap2Wireless Communication and Networking  by WilliamStallings Chap2
Wireless Communication and Networking by WilliamStallings Chap2
 
wireless communication and networking Chapter 1
wireless communication and networking Chapter 1wireless communication and networking Chapter 1
wireless communication and networking Chapter 1
 
WML Script by Shanti katta
WML Script by Shanti kattaWML Script by Shanti katta
WML Script by Shanti katta
 
WAP- Wireless Application Protocol
WAP- Wireless Application ProtocolWAP- Wireless Application Protocol
WAP- Wireless Application Protocol
 
What is WAP?
What is WAP?What is WAP?
What is WAP?
 
Introduction to Mobile Application Development
Introduction to Mobile Application DevelopmentIntroduction to Mobile Application Development
Introduction to Mobile Application Development
 
Markup Languages
Markup Languages Markup Languages
Markup Languages
 
MOBILE APPs DEVELOPMENT PLATFORMS
MOBILE APPs DEVELOPMENT PLATFORMSMOBILE APPs DEVELOPMENT PLATFORMS
MOBILE APPs DEVELOPMENT PLATFORMS
 
Introduction to wireless application protocol (wap)ogi
Introduction to wireless application protocol (wap)ogiIntroduction to wireless application protocol (wap)ogi
Introduction to wireless application protocol (wap)ogi
 
XML Programming WML by Dickson K.W. Chiu PhD, SMIEEE
XML Programming WML by Dickson K.W. Chiu PhD, SMIEEEXML Programming WML by Dickson K.W. Chiu PhD, SMIEEE
XML Programming WML by Dickson K.W. Chiu PhD, SMIEEE
 
Wireless Application Protocol WAP by Alvinen
Wireless Application Protocol WAP by AlvinenWireless Application Protocol WAP by Alvinen
Wireless Application Protocol WAP by Alvinen
 
HR QUESTIONS, INTERVIEW QUESTIONS
HR QUESTIONS, INTERVIEW QUESTIONSHR QUESTIONS, INTERVIEW QUESTIONS
HR QUESTIONS, INTERVIEW QUESTIONS
 
HR QUESTIONS
HR QUESTIONSHR QUESTIONS
HR QUESTIONS
 
STOCK APPLICATION USING CORBA
STOCK APPLICATION USING CORBASTOCK APPLICATION USING CORBA
STOCK APPLICATION USING CORBA
 
Zone Routing Protocol (ZRP)
Zone Routing Protocol (ZRP)Zone Routing Protocol (ZRP)
Zone Routing Protocol (ZRP)
 
On-Demand Multicast Routing Protocol
On-Demand Multicast Routing ProtocolOn-Demand Multicast Routing Protocol
On-Demand Multicast Routing Protocol
 
Adhoc routing protocols
Adhoc routing protocolsAdhoc routing protocols
Adhoc routing protocols
 
DSDV VS AODV
DSDV VS AODV DSDV VS AODV
DSDV VS AODV
 
16.Distributed System Structure
16.Distributed System Structure16.Distributed System Structure
16.Distributed System Structure
 
15.Security
15.Security15.Security
15.Security
 

Dernier

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Dernier (20)

Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

RSA alogrithm

  • 1. RSA We sometimes need to hide our confidential data from other users. For that purpose we use encryption algorithms to encrypt our data. There are very many encryption algorithms but I am describing the Rivest, Shamir, Adleman (RSA) Algorithm. RSA is an encryption algorithm. Developed in: 1977. Developed by: Ron Rivest, Adi Shamir, and Leonard Adleman. The RSA algorithm is the most commonly used public key encryption algorithm. Public Key Encryption It is also known as asymmetric cryptography. Two keys are used: Public Key and Private Key. Public Key: For encryption. Private Key: For decryption, also known as a secret key. The preceding diagram show how public key encryption works, In the diagram 2 users are shown: First: The Sender (who is sending something by the recipient's Public Key) Second: The Receiver (who is receiving something from the sender using the private key) So in a public key cryptosystem, the sender encrypts the data using the public key of the receiver and uses an encryption algorithm that is also decided by the receiver and the receiver sends only the encryption algorithm and public key.
  • 2. But by using the public key, data can only be encrypted but not decrypted, and the data is only decrypted by the private key that only the receiver has. So no one can hack our data. In simple terms: Public Key: Shared with the public that wants to send us data. Private Key: Kept secret so that when someone sends us data encrypted by our Public Key, we can decrypt the data using the Private Key. HOW RSA WORKS Both users (sender and receiver) generates a public and private key. The following is the procedure for generating a public and private key (see flowchart). Generation of Public and Private key in RSA The flowcharts above shows how to generate a public and private key using RSA. After getting the public and private key the main thing is how to encrypt and decrypt using RSA. Encryption and Decryption in RSA
  • 3. encrypt and decrypt.png Example of RSA: Here is an example of RSA encryption and decryption with generation of the public and private key. Generate public and private key: Encryption and Decryption
  • 4. How to use the RSA Algorithm in a C# Windows Forms application 1. Open Visual Studio. 2. Select "File" -> "New" -> "Project..." or press "Ctrl +Shift +N". 3. Now select "Windows Forms application" from the Visual C# templates. 4. Now design the Windows Forms form such as follows: You need to make:
  • 5. 3 TextBoxes for Plain Text, Encrypted Text and Decrypted Text and 2 Buttons. Now for the coding part. Coding 1. To use the RSA algorithm in C#, we need to add the following namespace: using System.Security.Cryptography; 2. Now make a function for Encryption. static public byte[] Encryption(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding) { try { byte[] encryptedData; using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider()) { RSA.ImportParameters(RSAKey); encryptedData = RSA.Encrypt(Data, DoOAEPPadding); } return encryptedData; } catch (CryptographicException e) { Console.WriteLine(e.Message); return null; } } 3. Now make a function for Decryption static public byte[] Decryption(byte[]Data, RSAParameters RSAKey, bool DoOAEPPadding) { try { byte[] decryptedData; using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider()) { RSA.ImportParameters(RSAKey); decryptedData = RSA.Decrypt(Data, DoOAEPPadding); } return decryptedData; } catch (CryptographicException e) { Console.WriteLine(e.ToString()); return null;
  • 6. } } 4. Now make some variables into the class that are: UnicodeEncoding ByteConverter = new UnicodeEncoding(); RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); byte[] plaintext; byte[] encryptedtext; 5. Now handle the Click Event for the Encrypt Button with the following code: private void button1_Click(object sender, EventArgs e) { plaintext = ByteConverter.GetBytes(txtplain.Text); encryptedtext = Encryption(plaintext, RSA.ExportParameters(false), false); txtencrypt.Text = ByteConverter.GetString(encryptedtext); } 6. Now handle the Click Event for the Decrypt Button with the following code: private void button2_Click(object sender, EventArgs e) { byte[] decryptedtex = Decryption(encryptedtext, RSA.ExportParameters(true), false); txtdecrypt.Text = ByteConverter.GetString(decryptedtex); } Results
  • 7. Plain Text: Encrypted Text: Decrypted Text: