Are salts useless for security if the attacker knows them?

后端 未结 7 1561
误落风尘
误落风尘 2021-02-14 11:14

Let\'s say I have a table of users set up like this:

CREATE TABLE `users` (
    `id` INTEGER PRIMARY KEY,
    `name` TEXT,
    `hashed_password` TEXT,
    `salt`         


        
7条回答
  •  温柔的废话
    2021-02-14 11:20

    This should give you an idea of how it works.

    Lets say you want to encrypt a word "secret." After it is encrypted lets say it now looks like this 00110010.

    If a hacker knows the encryption algorithm, they can create a table of words and their corresponding encrypted values. So they take the encrypted password "00110010" and find it in the table. Now they know that the password used to generate "00110010" was the word "secret." If you salt the word first, then a generic lookup table will be useless to the hacker. (A generic lookup table being a table of unsalted dictionary words and their encrypted values)

    If you salt the word first ("saltsecret"), now the encrypted value will look different, and the hacker wont find it in the lookup table.

    However, they can still start creating their own lookup table from scratch using your salt and eventually they will be able to reverse lookup passwords.

    So to answer the question, if the passwords are sufficiently complex, it will take ages for the hacker to figure them out. You could change your salt every year and they would have to start creating a table all over again.

提交回复
热议问题