Sunday, August 22, 2010

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

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.
  1. 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)  



  •         {