C# MD5加密

MD5加密小记


话不多说,上代码

密码加密的具体方法
public string Encrypt(string username, string password)
{
    //首次加密
    MD5 md5 = MD5.Create();
    byte[] bs = Encoding.UTF8.GetBytes(password + username);
    byte[] hs = md5.ComputeHash(bs);
    StringBuilder sb = new StringBuilder();
    foreach (byte b in hs)
    {
        sb.Append(b.ToString("x2"));
    }

    //再次加密
    byte[] nbs = Encoding.UTF8.GetBytes(sb.ToString() + username);
    byte[] nhs = md5.ComputeHash(nbs);
    StringBuilder nsb = new StringBuilder();
    foreach (byte nb in nhs)
    {
        nsb.Append(nb.ToString("x2"));
    }

    return nsb.ToString();
}

完结,撒花

©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页