WebForm:

private string GetMd5(string ps)
        {
            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(ps,"MD5");
        }

WinForm

string GetMd5(string ps)
        {
            MD5 md5 = MD5.Create();
            string pwd = "";
            byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(ps));

            // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
            for (int i = 0; i < s.Length; i++)
            {
                // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符

                pwd = pwd + s[i].ToString("x2");

            }
            return pwd.ToUpper();
        }

相关文章:

  • 2021-07-26
  • 2021-12-21
  • 2022-12-23
  • 2021-08-01
  • 2022-02-18
  • 2022-12-23
  • 2021-07-28
猜你喜欢
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
相关资源
相似解决方案