Design the Form as Following
<div>
<asp:TextBox ID="txtEncrypt" runat="server"></asp:TextBox>
<asp:Button ID="btnEncrypt" runat="server" Text="Encrypt" OnClick="btnEncrypt_Click" />
<asp:TextBox ID="txtDencrypt" runat="server"></asp:TextBox>
<asp:Button ID="btnDencrpt" runat="server" Text="Dencrypt" OnClick="btnDencrpt_Click" />
</div>
Add New Item and a add a new class File with the name
EncryptDencrypt.cs
Add the following Namespaces
using System.Security.Cryptography;
using System.Text;
write the following code
public class EncryptDencrypt
{
TripleDESCryptoServiceProvider tdc;
MD5CryptoServiceProvider mdcs;
public EncryptDencrypt()
{
tdc = new TripleDESCryptoServiceProvider();
mdcs = new MD5CryptoServiceProvider();
}
public string Encryption(string Data)
{
Byte[] eNC_data = ASCIIEncoding.ASCII.GetBytes(Data);
string eNC_str = Convert.ToBase64String(eNC_data);
return eNC_str;
}
public string Decryption(string Data)
{
Byte[] dEC_data = Convert.FromBase64String(Data);
string dEC_Str =ASCIIEncoding.ASCII.GetString(dEC_data);
return dEC_Str;
}
}
Write the following code in .cs page
protected void btnEncrypt_Click(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(txtEncrypt.Text))
{
EncryptDencrypt objency=new EncryptDencrypt();
txtDencrypt.Text=objency.Encryption(txtEncrypt.Text);
}
}
protected void btnDencrpt_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtDencrypt.Text))
{
EncryptDencrypt objdency = new EncryptDencrypt();
txtEncrypt.Text = objdency.Decryption(txtDencrypt.Text);
}
}
Enter the text and click on Encrypt Button
Next Enter any Dencrpt Text and Click on Dencrpt and see the output.
No comments:
Post a Comment
Thank you for visiting my blog