Public Key Encryption and Decryption in ASP.NET

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. using System.Collections;  
  10. using System.Diagnostics;  
  11. using System.Security;  
  12. using System.Security.Cryptography;  
  13. using System.IO;  
  14. namespace Public_Key_Encryption   
  15. {  
  16.     public partial class Form1: Form   
  17.     {  
  18.         public Form1()  
  19.         {  
  20.             InitializeComponent();  
  21.         }  
  22.         public static void main()  
  23.         {  
  24.             RSACryptoServiceProvider myRSAProvide = new RSACryptoServiceProvider();  
  25.             string strCrypt = null;  
  26.             byte[] bteCrypt = null;  
  27.             byte[] bteResult = null;  
  28.             try   
  29.             {  
  30.                 strCrypt = "golivecode.com";  
  31.                 bteCrypt = Encoding.ASCII.GetBytes(strCrypt);  
  32.                 bteResult = myRSAProvide.Encrypt(bteCrypt, false);  
  33.                 MessageBox.Show(Encoding.ASCII.GetString(bteResult));  
  34.             }  
  35.             catch (CryptographicException ex)  
  36.             {  
  37.                 Console.WriteLine(ex.Message);  
  38.             }  
  39.             string strResault = null;  
  40.             byte[] bteDecrypt = null;  
  41.             try   
  42.             {  
  43.                 bteDecrypt = myRSAProvide.Decrypt(bteResult, false);  
  44.                 strResault = Encoding.ASCII.GetString(bteDecrypt);  
  45.             }  
  46.             catch (CryptographicException ex)   
  47.             {  
  48.                 MessageBox.Show(ex.Message);  
  49.             }  
  50.             Console.ReadLine();  
  51.         }  
  52.         private void button1_Click(object sender, EventArgs e)   
  53.         {  
  54.             //Class1 obj = new Class1();  
  55.             //obj.mess();  
  56.             main();  
  57.         }  
  58.     }  
  59. }