Difference between Hashing a Password and Encrypting it

前端 未结 9 668
野的像风
野的像风 2020-11-22 02:46

The current top-voted to this question states:

Another one that\'s not so much a security issue, although it is security-related, is complete and abje

相关标签:
9条回答
  • 2020-11-22 03:00

    Hashing is a one-way function, meaning that once you hash a password it is very difficult to get the original password back from the hash. Encryption is a two-way function, where it's much easier to get the original text back from the encrypted text.

    Plain hashing is easily defeated using a dictionary attack, where an attacker just pre-hashes every word in a dictionary (or every combination of characters up to a certain length), then uses this new dictionary to look up hashed passwords. Using a unique random salt for each hashed password stored makes it much more difficult for an attacker to use this method. They would basically need to create a new unique dictionary for every salt value that you use, slowing down their attack terribly.

    It's unsafe to store passwords using an encryption algorithm because if it's easier for the user or the administrator to get the original password back from the encrypted text, it's also easier for an attacker to do the same.

    0 讨论(0)
  • 2020-11-22 03:01

    Ideally you should do both.

    First Hash the pass password for the one way security. Use a salt for extra security.

    Then encrypt the hash to defend against dictionary attacks if your database of password hashes is compromised.

    0 讨论(0)
  • 2020-11-22 03:02

    As correct as the other answers may be, in the context that the quote was in, hashing is a tool that may be used in securing information, encryption is a process that takes information and makes it very difficult for unauthorized people to read/use.

    0 讨论(0)
  • 2020-11-22 03:08

    Hashing:

    It is a one-way algorithm and once hashed can not rollback and this is its sweet point against encryption.

    Encryption

    If we perform encryption, there will a key to do this. If this key will be leaked all of your passwords could be decrypted easily.

    On the other hand, even if your database will be hacked or your server admin took data from DB and you used hashed passwords, the hacker will not able to break these hashed passwords. This would actually practically impossible if we use hashing with proper salt and additional security with PBKDF2.

    If you want to take a look at how should you write your hash functions, you can visit here.

    There are many algorithms to perform hashing.

    1. MD5 - Uses the Message Digest Algorithm 5 (MD5) hash function. The output hash is 128 bits in length. The MD5 algorithm was designed by Ron Rivest in the early 1990s and is not a preferred option today.

    2. SHA1 - Uses Security Hash Algorithm (SHA1) hash published in 1995. The output hash is 160 bits in length. Although most widely used, this is not a preferred option today.

    3. HMACSHA256, HMACSHA384, HMACSHA512 - Use the functions SHA-256, SHA-384, and SHA-512 of the SHA-2 family. SHA-2 was published in 2001. The output hash lengths are 256, 384, and 512 bits, respectively,as the hash functions’ names indicate.

    0 讨论(0)
  • 2020-11-22 03:09

    I've always thought that Encryption can be converted both ways, in a way that the end value can bring you to original value and with Hashing you'll not be able to revert from the end result to the original value.

    0 讨论(0)
  • 2020-11-22 03:12

    Hashing is a one way function (well, a mapping). It's irreversible, you apply the secure hash algorithm and you cannot get the original string back. The most you can do is to generate what's called "a collision", that is, finding a different string that provides the same hash. Cryptographically secure hash algorithms are designed to prevent the occurrence of collisions. You can attack a secure hash by the use of a rainbow table, which you can counteract by applying a salt to the hash before storing it.

    Encrypting is a proper (two way) function. It's reversible, you can decrypt the mangled string to get original string if you have the key.

    The unsafe functionality it's referring to is that if you encrypt the passwords, your application has the key stored somewhere and an attacker who gets access to your database (and/or code) can get the original passwords by getting both the key and the encrypted text, whereas with a hash it's impossible.

    People usually say that if a cracker owns your database or your code he doesn't need a password, thus the difference is moot. This is naïve, because you still have the duty to protect your users' passwords, mainly because most of them do use the same password over and over again, exposing them to a greater risk by leaking their passwords.

    0 讨论(0)
提交回复
热议问题