该算法的Base64编码盐/密码的最大长度是多少?

5
以下是我正在重写的应用程序中用于哈希密码的代码片段:
    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编码盐和密码的最大长度是多少?

1个回答

16

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接