Reader Level:
Articles

Public Key Encryption (RSA Method) for Encryption and Decryption in ASP.Net

By Brijesh Jalan on August 19, 2010
In this article we will learn how use Public Key Encryption for Encryption and Decryption in ASP.Net
  • 0
  • 0
  • 17075

We already know about DES algorithm  method

The RSA Public Key Encryption is useful method for Encryption and Decryption .The Code behind the Method is mention below.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.IO; 

public
class Tester

    public static void Main()
    {
        RSACryptoServiceProvider myRSAProvide = new RSACryptoServiceProvider();
        string strCrypt = null;
        byte[] bteCrypt = null;
        byte[] bteResult = null;
        try
        {
            strCrypt = "12345678";
            bteCrypt = Encoding.ASCII.GetBytes(strCrypt);
            bteResult = myRSAProvide.Encrypt(bteCrypt, false);
            Console.WriteLine(Encoding.ASCII.GetString(bteResult));
         }
        catch (CryptographicException ex)
        {
            Console.WriteLine(ex.Message);
        }
         string strResault = null;
        byte[] bteDecrypt = null;
        try
        {
            bteDecrypt = myRSAProvide.Decrypt(bteResult, false);
            strResault = Encoding.ASCII.GetString(bteDecrypt);
            Console.WriteLine(strResault);
        }
        catch (CryptographicException ex)
        {
            Console.WriteLine(ex.Message);
        }
         Console.ReadLine();
    }
}

It is very simple pubic key encryption and decryption method.

Brijesh Jalan

Brijesh Jalan has been working as a software engineer since 2010. He has written articles for C# Corner . He specializes in the implementation of client/server, database, graphics and/or Internet-based systems using Visu... Read more

COMMENT USING

Trending up