zoukankan      html  css  js  c++  java
  • C# MD5加密字符串

    /// <summary>
    /// 用MD5加密字符串,可选择生成16位或者32位的加密字符串
    /// </summary>
    /// <param name="password">待加密的字符串</param>
    /// <param name="bit">位数,一般取值16 或 32</param>
    /// <returns>返回的加密后的字符串</returns>
    public string MD5Encrypt(string password, int bit)
    {
    MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
    byte[] hashedDataBytes;
    hashedDataBytes = md5Hasher.ComputeHash(Encoding.GetEncoding("gb2312").GetBytes(password));
    StringBuilder tmp = new StringBuilder();
    foreach (byte i in hashedDataBytes)
    {
    tmp.Append(i.ToString("x2"));
    }
    if (bit == 16)
    return tmp.ToString().Substring(8, 16);
    else
    if (bit == 32) return tmp.ToString();//默认情况
    else return string.Empty;
    }
    /// <summary>
    /// 用MD5加密字符串
    /// </summary>
    /// <param name="password">待加密的字符串</param>
    /// <returns></returns>
    public string MD5Encrypt(string password)
    {
    MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
    byte[] hashedDataBytes;
    hashedDataBytes = md5Hasher.ComputeHash(Encoding.GetEncoding("gb2312").GetBytes(password));
    StringBuilder tmp = new StringBuilder();
    foreach (byte i in hashedDataBytes)
    {
    tmp.Append(i.ToString("x2"));
    }
    return tmp.ToString();
    }

    命名空间:System.Security.Cryptography.MD5CryptoServiceProvider 

  • 相关阅读:
    Django——form组件和ModelForm
    CDH hadoop的安装
    Vulnhub-靶机-PRIME: 1
    Vulnhub-靶机-SYMFONOS: 5
    sqlilab-Less-21-30-writeup
    Vulnhub-靶机-SYMFONOS: 4
    Vulnhub-靶机-SYMFONOS: 3
    基础汇总-sqlilab-Less-1-20
    sqlilab-Less-13-19 测试writeup
    sqlilab-Less-9-12 测试writeup
  • 原文地址:https://www.cnblogs.com/xifengyeluo/p/8215062.html
Copyright © 2011-2022 走看看