实现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)
{
}
}
}
具体效果就这样了,修改下其中的MD5加密方法,也可用于做汇率转换等其他功能。