需导入 using System.Security.Cryptography;
public static class MD5Crypto
{
//MD5加密(生成32位字符码)
public static string Encrypt(string input)
{
//注意: 编码不同,生成的MD5值也不同
byte[] buffer = Encoding.UTF8.GetBytes(input);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] res = md5.ComputeHash(buffer);
return BitConverter.ToString(res).Replace("-", "");
}
//密码混淆字符串
public const string PASSWORD_PREFIX = "QwErT#2020&$kLjKNM986sljk@";
public const string PASSWORD_POSTFIX = "Iklsn%$#@LIl.rXVPo^#123@";
public static string EncryptPassword(string password)
{
string mix_password = string.Format("{0}{1}{2}", PASSWORD_PREFIX, password, PASSWORD_POSTFIX);
return Encrypt(mix_password);
}
}