using System.Text; using System.Security.Cryptography; namespace Tool { public class PasswordHelper { /// <summary> /// MD5 加密字符串 /// </summary> /// <param name="rawPass">源字符串</param> /// <returns>加密后字符串</returns> private string MD5Encoding(string rawPass) { // 创建MD5类的默认实例:MD5CryptoServiceProvider MD5 md5 = MD5.Create(); byte[] bs = Encoding.UTF8.GetBytes(rawPass); byte[] hs = md5.ComputeHash(bs); StringBuilder stb = new StringBuilder(); foreach (byte b in hs) { // 以十六进制格式格式化 stb.Append(b.ToString("x2")); } return stb.ToString(); } /// <summary> /// MD5盐值加密 /// </summary> /// <param name="rawPass">源字符串</param> /// <param name="salt">盐值</param> /// <returns>加密后字符串</returns> public string MD5Encoding(string rawPass, object salt) { if (salt == null) return rawPass; return MD5Encoding(rawPass + "{" + salt.ToString() + "}"); } } }
---------------------
作者:RayWang80s
来源:CSDN
原文:https://blog.csdn.net/raywang80s/article/details/77449129
版权声明:本文为博主原创文章,转载请附上博文链接!