My code will really take 8 years or so to decrypt

While reading the Hashing topic in C # in a nutshell, I came across the following quotes!

You can provide additional protection against attacks with dictionaries “stretching” your password hashes - repeated repetition to get more computationally intensive byte sequences. If you rephrase 100 times, a dictionary attack, which might otherwise take 1 month, will take 8 years.

So, I implemented it like this!

byte[] data = Encoding.UTF8.GetBytes("Password is 12345679"); byte[] hash = SHA512.Create().ComputeHash(data); int temp=0; while (temp < 100) { hash = SHA512.Create().ComputeHash(hash); temp++; } 

Is the above code correct? Will a dictionary attack really take about 8 years?

+4
source share
3 answers

In the absence of shortcuts (as @ Random832 noted), you should expect it to take 100 times to check for brute force that it hashed 100 times as a whole. If an attacker looks at each sequence of characters that look for a hash that matches, then everything that makes this hash longer slows it down (or, which is the same thing, uses more processing power).

Continuing to steal from Random832, this is a "poor man." This is adequate and useful, but if you have the PBKDF2 function, it is preferable since PBKDF2 is well analyzed by cryptographers. In the strict sense, your code above is Password Based Key Detection Function (PBKDF), but PBKDF2 is specific. EDIT: I'm not a C # developer by profession, but it looks like this: .NET includes the PBKDF2 function Rfc2898DeriveBytes .

Note the key phrase in the text above: “otherwise it may take 1 month.” The writer suggests that it takes a month to do the first, and 8 years - about 100 months. If it would take 1 minute to perform a dictionary attack in the first place, you should expect the second to take about 1.5 hours. There is no "8 years old" magic here. This is just a 100x first number, regardless of what the first number is.

EDIT: Another thing regarding stretching. You should always salt before stretching. Salting means that you add a random sequence of bytes to the beginning of the password. Then you encode this salt along with the result of the hash (salt is not a secret). So instead of hashing the “Password 12345679”, you will have the hash “deadbeefPassword 12345679” and then you will send “deadbeef” to clear along with the final result. The reason you do this is because people always choose the same passwords. Therefore, if an attacker generates a hash result of "Passw0rd!" then he could just check this result against your hash. Cheaper. Similarly, if he had the hashes of Alice and Bob, he could tell if they were the same or different. But with a random salt, you cannot do this, since almost certainly Alice and Bob will have their own hashed data with different salts.

+6
source

This is wrong, you just make another hash that has the same general characteristics as the original hash.

-2
source

A good hacker will fool you by visiting a website salty with any of a dozen exploits, use it like toehold to get the keystroke logger installed on your computer, and then email the log of everything you type for the next month or two . This hacker will be without your password.

-4
source

Source: https://habr.com/ru/post/1401809/


All Articles