using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Security.Cryptography; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } byte[] encrypted; private void button1_Click(object sender, EventArgs e) { TripleDESCryptoServiceProvider triple = new TripleDESCryptoServiceProvider(); UTF8Encoding u = new UTF8Encoding(); MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); triple.Key = md5.ComputeHash(u.GetBytes(textBox1.Text)); triple.Mode = CipherMode.ECB; triple.Padding = PaddingMode.PKCS7; ICryptoTransform trans = triple.CreateEncryptor(); encrypted = trans.TransformFinalBlock(u.GetBytes(textBox2.Text), 0, u.GetBytes(textBox2.Text).Length); textBox3.Text = BitConverter.ToString(encrypted); } private void button2_Click(object sender, EventArgs e) { TripleDESCryptoServiceProvider triple = new TripleDESCryptoServiceProvider(); MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); UTF8Encoding u = new UTF8Encoding(); triple.Key = md5.ComputeHash(u.GetBytes(textBox1.Text)); triple.Mode = CipherMode.ECB; triple.Padding = PaddingMode.PKCS7; ICryptoTransform trans = triple.CreateDecryptor(); textBox5.Text = u.GetString(trans.TransformFinalBlock(encrypted, 0, encrypted.Length)); } } }
Quote:Newer hash functions such as the Secure Hash Algorithms SHA-256 and SHA-512 are available. Consider using the SHA256 class or the SHA512 class instead of the MD5CryptoServiceProvider class. Use MD5CryptoServiceProvider only for compatibility with legacy applications and data.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)