Difference between Hashing and Encrypting
2012-10-16 00:00
525 查看
http://stackoverflow.com/questions/326699/difference-between-hashing-a-password-and-encrypting-it
http://thomashunter.name/blog/password-encryption-hashing-salting-explained/ http://thomashunter.name/blog/per-user-password-hashing-algorithms/ http://thomashunter.name/blog/external-salted-password-hashing/ http://crackstation.net/hashing-security.htm
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 contrarrest 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.
To be clear, get the desired security with the hash, it must be a cryptographically secure hash algorithm with the specific property that not only the hash be non-reversable BUT ALSO computationally impractical to generate ANY other string that generates the same hash.
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.
Always hash passwords.
http://thomashunter.name/blog/password-encryption-hashing-salting-explained/ http://thomashunter.name/blog/per-user-password-hashing-algorithms/ http://thomashunter.name/blog/external-salted-password-hashing/ http://crackstation.net/hashing-security.htm
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 contrarrest 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.
To be clear, get the desired security with the hash, it must be a cryptographically secure hash algorithm with the specific property that not only the hash be non-reversable BUT ALSO computationally impractical to generate ANY other string that generates the same hash.
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.
Always hash passwords.
相关文章推荐
- Difference between start and run method in Thread – Java Tutorial
- Know Difference between Oracle Reserved Words and Keywords
- vSphere 6.0 -Difference between vSphere 5.0, 5.1, 5.5 and vSphere 6.0
- What is the difference between a = a * (2^3) and a = a << 3?
- The difference between Framework and Library
- The difference between the request time and the current time is too large.阿里云oss上传图片报错
- What are the difference between DDL, DML and DCL commands?
- Differences Between Modal and Modeless Dialog Boxes
- Is there a difference between `==` and `is` in Python?
- Slight difference between C++ and C
- Difference between prototype and this in JavaScript
- 10 Major Differences Between C And C++
- The difference between Language Interface Pack (LIP) and Language Pack (LP)
- what is the difference between processes and threads
- The difference between NAS and SAN
- What is the difference between CDATA and PCDATA?
- Difference between fflush and fsync
- What is the difference between Constructor and ngOnInit?
- Know Difference between Oracle Reserved Words and Keywords
- what is the difference between _source and _all in Elasticsearch