private void btnOK_Click(object sender, EventArgs e)
{
txtMD5.Text = "";
if (string .IsNullOrEmpty (txtPassword .Text .Trim ()))
{
MessageBox.Show("请输入密码!");
return;
}
string MD5Pwd = Encrypt(txtPassword.Text.Trim());
txtMD5.Text = MD5Pwd;
//MessageBox.Show(MD5Pwd);
}
/// <summary>
/// 加密
/// </summary>
/// <param name="strPwd"></param>
/// <returns></returns>
public string Encrypt(string strPwd)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] data = System.Text.Encoding.Default.GetBytes(strPwd);//将字符编码为一个字节序列
byte[] md5data = md5.ComputeHash(data);//计算data字节数组的哈希值
md5.Clear();
string str = "";
for (int i = 0; i < md5data.Length - 1; i++)
{
str += md5data[i].ToString("x").PadLeft(2, '0');
}
return str;
}