簡單的MD5加密器,
阿新 • • 發佈:2018-12-09
實現c#輸入文字框中的字串改變使另外一個文字框文字輸出MD5加密值也實時變化。
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; namespace WindowsFormsApplication1 { public partial class Form1 : Form { private string a; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } public string EncodePassword(string pwd) { //獲取要加密的欄位,並轉化為Byte[]陣列 byte[] data = System.Text.Encoding.Unicode.GetBytes(pwd.ToCharArray()); //建立加密服務 System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); //加密Byte[]陣列 byte[] result = md5.ComputeHash(data); //將加密後的陣列轉化為欄位 return System.Text.Encoding.Unicode.GetString(result); } private void textBox1_TextChanged(object sender, EventArgs e) { textBox2.Text = EncodePassword(textBox1.Text.Trim()); } private void textBox2_TextChanged(object sender, EventArgs e) { } } }
具體效果就這樣了,