MD5 加密
/// <summary> /// Web 转换MD5 /// </summary> /// <param name="str">字符</param> /// <param name="code">32或64位</param> /// <returns></returns> public static string MD5(string str, int code)
{ if (code == 16) { return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16); } if (code == 32) { return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5"); } return "00000000000000000000000000000000"; }
//MD5 正常加密
public static string HashString(string str) {
MD5 md5=MD5.Create();
byte[] source = md5.ComputeHash(Encoding.Default.GetBytes(str));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < source.Length; i++)
{
sb.Append(source[i].ToString("x"));
}
return sb.ToString();
}