命名空间 using System.Security.Cryptography; //加密引入的命名空间
#region MD5加密
public string GetMD5(string PWD)
{
System.Security.Cryptography.MD5CryptoServiceProvider md5CSP = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] md5Source = System.Text.Encoding.Unicode.GetBytes(PWD);
byte[] md5Out = md5CSP.ComputeHash(md5Source);
string sTemp = "";
for (int i = 0; i < md5Out.Length; i++)
{
sTemp += md5Out[i].ToString("x").PadLeft(2, '0');
}
return sTemp;
}
#endregion
*************使用方法: //string pwd = (new UserDAO()).GetMD5(txtPwd.Text); //将密码加密