MD5加密
1.引用命名空间
using System.Security.Cryptography;
2.编码
/**
* MD5加密
* @return MD5加密结果
*/
public static string EncryptByMD5(string cleartext)
{
cleartext = cleartext.Trim();
using (MD5CryptoServiceProvider md5Provider = new MD5CryptoServiceProvider())
{
byte[] hashBytes = md5Provider.ComputeHash(Encoding.UTF8.GetBytes(cleartext));
var builder = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
builder.Append(hashBytes[i].ToString("x2"));
}
return builder.ToString();
}
}