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();
        }

 

posted @ 2019-06-18 15:44  张伟大  阅读(140)  评论(0编辑  收藏  举报