Password Hashing - Why salt 60,000 times

旧街凉风 提交于 2019-12-05 11:05:42

I do not get why for passwords i'm not being told to use bcrypt or another equivalent that is slow

I'm guessing this is why they're asking you to hash 60000 time. To add a work factor and slow down brute force attacks.

How do I make this hashing to work properly?

Something like this:

using (var sha256 = SHA256.Create())
{
    string password = "hovercraft";

    // step 1: you can use RNGCryptoServiceProvider for something worth using
    string salt = GenerateSalt();

    // step 2
    string hash = 
       Convert.ToBase64String(sha256.ComputeHash(Encoding.UTF8.GetBytes(salt + password)));

    // step 3
    byte[] result = sha256.ComputeHash(Encoding.UTF8.GetBytes(salt + hash));

    // step 4
    for (int i = 0; i < 60000; i++)
    {
        result = 
         sha256.ComputeHash(Encoding.UTF8.GetBytes(salt + Convert.ToBase64String(result)));
    }
}

To me this looks like an attempt to reimplement a PBKDF2 algorithm, to get a cost factor.

Usually it is not recommended to make experiments with security functions, instead one should use a proven well tested algorithm. Your concern about the algorithm above is justified, try to convince your team to switch to BCrypt.Net or to PBKDF2.

When you go for PBKDF2, then you can either use the built in dotnet class Rfc2898DeriveBytes to calculate a PBKDF2 with HMACSHA1 (which is the standard even today), or you can use an implementation which supports other hash functions like PBKDF2 with SHA-256.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!