.net中MD5过时,使用新的MD5方法

原有项目的MD5算法提示过时,形如:return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5")

使用新的MD5方法。

 public class MD5Helper
    {
        /// <summary>
        /// 推荐
        /// 默认大写 32位加密
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string GetMd5_32(string str)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] bytes = Encoding.UTF8.GetBytes(str);
            string result = BitConverter.ToString(md5.ComputeHash(bytes));
            return result.Replace("-", "");
        }

        /// <summary>
        /// 默认大写 16位加密
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string GetMd5_16(string str)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] bytes = Encoding.UTF8.GetBytes(str);
            string result = BitConverter.ToString(md5.ComputeHash(bytes), 4, 8);
            return result.Replace("-", "");
        }
    }

引用:

https://blog.csdn.net/u011127019/article/details/51384246

 

posted @ 2022-04-13 17:09  阿日斯兰  阅读(226)  评论(0编辑  收藏  举报