前言:网上MD5加密的算法已经很多了,但找了几个,还是和我这个不太一样,所以还是写下来吧,仅供参考。
注意要写在WEB下面的APP_CODE下面,如果写在类库里,没有相应的命名空间,呵呵。好了,费话少说,见代码:

using System.Security.Cryptography;

/// <summary>
/// MD5 加密
/// </summary>
public class MD5
{
    public MD5()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    /// <summary>
    /// MD5 加密函数
    /// </summary>
    /// <param name="str"></param>
    /// <param name="code">16or32</param>
    /// <returns></returns>
    public static string getMD5(string str, int code)
    {

        if (code == 16) //16位加密
        {
            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
        }

        else if (code == 32) //32位加密
        {
            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5");
        }
        return "0";
    }
}

相关文章:

  • 2021-09-16
  • 2022-01-07
  • 2022-01-01
猜你喜欢
  • 2021-08-25
  • 2021-07-20
  • 2021-10-17
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
相关资源
相似解决方案