Encryption of data is mandatory followed in some
networks or in saving passwords to the database. So encrypting the data and
decrypting the already encrypted code has been logged here.
Here there is two functions Encrypt and Decrypt to
convert the data, find the below code for reference.
ASP.Net
Code
<html>
<head runat="server">
<title>Encrypt and Decrypt: fourthbottle</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnencrypt" runat="server" Text="Encrypt"
onclick="btnencrypt_Click"
/>
</td>
<td>
<asp:Button ID="btndecrypt"
runat="server"
Text="Decrypt"
onclick="btndecrypt_Click"
/>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
C#
Code
using System;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Text;
namespace JSVirtualKeyboard
{
public partial class WebForm2 :
System.Web.UI.Page
{
private string
Encrypt(string txttoEncrypt)
{
string EcriptedData = string.Empty;
byte[] txt_encode = new
byte[txttoEncrypt.Length];
txt_encode = Encoding.UTF8.GetBytes(txttoEncrypt);
EcriptedData = Convert.ToBase64String(txt_encode);
return EcriptedData;
}
private string Decrypt(string txttoDecrypt)
{
UTF8Encoding encode_pwd = new
UTF8Encoding();
string DecryptedData = string.Empty;
Decoder Decode = encode_pwd.GetDecoder();
byte[] todecodeByte = Convert.FromBase64String(txttoDecrypt);
int charCount = Decode.GetCharCount(
todecodeByte,
0,
todecodeByte.Length
);
char[] decoded_char = new
char[charCount];
Decode.GetChars(todecodeByte, 0, todecodeByte.Length, decoded_char, 0);
DecryptedData = new String(decoded_char);
return DecryptedData;
}
protected void
btnencrypt_Click(object sender, EventArgs e)
{
TextBox2.Text = Encrypt(TextBox1.Text);
}
protected void
btndecrypt_Click(object sender, EventArgs e)
{
TextBox1.Text = Decrypt(TextBox2.Text);
}
}
}
6 Comments
It’s a classic great for me to go to this blog site, it offers more helpful and wonderful suggestions.
ReplyDeleteJava Training in Bangalore
Best Java Training Institutes in Bangalore
Java Institutes in Bangalore
AWS Training in Bangalore
Devops Training in Bangalore
Python Training in Bangalore
Data Analytics Training in Bangalore
Digital Marketing Training in Bangalore
Robotics Courses in Bangalore
Nice post and more informative,thanks for sharing...
ReplyDeleteRPA training in bellandur
AWS Training in bellandur
Marathahalli AWS Training Institues
Kalyan nagar AWS training in institutes
Data Science Training in bellandur
Data Science Training in Kalyan Nagar
Data science training in marathahalli
I feel satisfied to read your blog, you have been delivering a useful & unique information to our vision.keep blogging.
ReplyDeletesalesforce Training in Bangalore
uipath Training in Bangalore
blueprism Training in Bangalore
Your post is just outstanding! thanx for such a post,its really going great and great work.
ReplyDeletepython training in kalyan nagar|python training in marathahalli
selenium training in marathahalli|selenium training in bangalore
devops training in kalyan nagar|devops training in bellandur
phthon training in bangalore
This post is very simple to read and appreciate without leaving any details out. Great work!
ReplyDeleteYou completed certain reliable points there. I did a search on the subject and found nearly all persons will agree with your blog.
Much thanks for composing such an intriguing article on this point. This has truly made me think and I plan to peruse more
ReplyDeletebusiness analytics course