ARTICLE

Implementation of RSA Algorithm of Cryptography in VB.NET

Posted by Shalini Juneja Articles | Cryptography in VB.NET May 12, 2011
In this article you will learn that how can you implement RSA Algorithm
Download Files:
 
Reader Level:

Introduction
 
Here in this article we are discussing about RSA Encryption algorithm of Cryptography. RSA Encryption was invented in 1977 by three guys by the names of Rivest,Shamir and Adlmn. This is where it get's its name. RSA is recommended for mainly Encrypting small amount of data,like password. The implementation of RSA needs to import the necessary namespaces then add controls and declare some variables these variables will used throughout our code. You will put these variables just under Public Class Form1.

Before we use RSA to Encrypt the data, you need to convert it into byte format with the UTF8 Encoder. So you are actually Encrypting the data twice. One from String to Byte and then Byte, to another Byte. The final line converts the Encrypted data from Byte format, to Base64 String format in order to display it in TextBox2. To get the original data you need to run the encrypted data through the RSA decryptor, Than through the UTF8 Encoder again, when you test this application, after clicking Encrypt Button to Encrypt the data, delete the contents of TextBox1. When you click Decrypt Button you should see the original text will appear in TextBox1.


Getting Started

  • Simply create a new Windows Application. 
  • Drag two Buttons and TextBox on your form. Your form will look like below.

    RSA1.gif
     
  • Now add the below code for implementation.

       
    Dim textbytes, encryptedtextbytes As Byte()
        Dim rsa As New RSACryptoServiceProvider
        Dim encoder As New UTF8Encoding
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim TexttoEncrypt As String = TextBox1.Text
            textbytes = encoder.GetBytes(TexttoEncrypt)
            encryptedtextbytes = rsa.Encrypt(textbytes, True)
            TextBox2.Text = Convert.ToBase64String(encryptedtextbytes)
        End Sub 
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            textbytes = rsa.Decrypt(encryptedtextbytes, True)
            TextBox1.Text = encoder.GetString(textbytes)
        End
    Sub

     
  • Now run your application.

Output:-

RSA2.gif

RSA3.gif

RSA4.gif

RSA5.gif

RSA7.gif

Summary

In this article you learned that how to implement RSA Algorithm.

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Diagram
Become a Sponsor