【问题标题】:Max length of base64 encoded salt/password for this algorithm此算法的 base64 编码盐/密码的最大长度
【发布时间】:2011-07-29 15:43:20
【问题描述】:

下面是我正在重写的应用程序中用于哈希密码的代码的 sn-p:

    internal string GenerateSalt()
    {
        byte[] buf = new byte[16];
        (new RNGCryptoServiceProvider()).GetBytes(buf);
        return Convert.ToBase64String(buf);
    }

    internal string EncodePassword(string pass, string salt)
    {
        byte[] bIn = Encoding.Unicode.GetBytes(pass);
        byte[] bSalt = Convert.FromBase64String(salt);
        byte[] bAll = new byte[bSalt.Length + bIn.Length];

        Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length);
        Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length);
        HashAlgorithm s = HashAlgorithm.Create("SHA512");
        byte[] bRet = s.ComputeHash(bAll);

        return Convert.ToBase64String(bRet);
    }

哈希密码和盐稍后将存储在数据库中。 base64 编码的盐和密码的最大长度是多少?

【问题讨论】:

    标签: c# sql-server encoding character-encoding base64


    【解决方案1】:

    由于 SHA-512 哈希始终为 512 位 = 64 字节,而 base64 需要 (n + 2 - ((n + 2) % 3)) / 3 * 4 字节,因此您将始终需要 88 字节来存储数据。

    【讨论】:

      猜你喜欢
      • 2011-03-03
      • 1970-01-01
      • 1970-01-01
      • 2010-09-16
      • 2014-09-05
      • 1970-01-01
      • 1970-01-01
      • 2018-01-22
      • 2011-11-19
      相关资源
      最近更新 更多