MD5加密
在.net 4.5版本下,使用System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile进行MD5加密时,会出现已过时提示,所以需要使用以下方法代替
/// <summary> /// 32位MD5加密 /// </summary> /// <param name="input">需要加密的字符串</param> /// <returns></returns> public static string Md5Hash(string input) { MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider(); byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input)); //Encoding.UTF8.GetBytes(input) StringBuilder sBuilder = new StringBuilder(); for (int i = 0; i < data.Length; i++) { sBuilder.Append(data[i].ToString("x2")); } return sBuilder.ToString(); }