using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Diagnostics;
using System.Security;
using System.Security.Cryptography;
using System.IO;
namespace Public_Key_Encryption
{
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
}
public static void main()
{
RSACryptoServiceProvider myRSAProvide = new RSACryptoServiceProvider();
string strCrypt = null;
byte[] bteCrypt = null;
byte[] bteResult = null;
try
{
strCrypt = "golivecode.com";
bteCrypt = Encoding.ASCII.GetBytes(strCrypt);
bteResult = myRSAProvide.Encrypt(bteCrypt, false);
MessageBox.Show(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);
}
catch (CryptographicException ex)
{
MessageBox.Show(ex.Message);
}
Console.ReadLine();
}
private void button1_Click(object sender, EventArgs e)
{
//Class1 obj = new Class1();
//obj.mess();
main();
}
}
}In this code snippet you will learn about Public Key Encryption and Decryption in ASP.NET.
