protected void Page_Load(object sender, EventArgs e) { InitializeComponent(); } protected void Button1_Click(object sender, EventArgs e) { byte[] buffer = Encryption(textBox1.Text, txtKey.Text); string b = Convert.ToBase64String(buffer); textBox1.Text = b; } public static byte[] Encryption(string PlainText, string key) { TripleDES des = CreateDES(key); ICryptoTransform ct = des.CreateEncryptor(); byte[] input = Encoding.Unicode.GetBytes(PlainText); return ct.TransformFinalBlock(input, 0, input.Length); } public static string Decryption(string CypherText, string key) { byte[] b = Convert.FromBase64String(CypherText); TripleDES des = CreateDES(key); ICryptoTransform ct = des.CreateDecryptor(); byte[] output = ct.TransformFinalBlock(b, 0, b.Length); return Encoding.Unicode.GetString(output); } static TripleDES CreateDES(string key) { MD5 md5 = new MD5CryptoServiceProvider(); TripleDES des = new TripleDESCryptoServiceProvider(); des.Key = md5.ComputeHash(Encoding.Unicode.GetBytes(key)); des.IV = new byte[des.BlockSize / 8]; return des; } protected void Button2_Click(object sender, EventArgs e) { textBox2.Text = Decryption(textBox1.Text, txtKey.Text); //textBox3.Text = Decryption(textBox2.Text, txtKey.Text); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)