Two Different Tools
People often confuse hashing and encryption, but they serve different goals.
Encryption is reversible. With the correct key you can recover the original plaintext. It protects confidentiality, keeping data readable only to key holders.
Hashing is one way. A cryptographic hash like SHA two hundred fifty six maps any input to a fixed size digest, and there is no key and no way to reverse it back to the input. It protects integrity and lets you compare values without storing them.
Choosing Correctly
- Use encryption when you must read the data again later, such as stored card numbers.
- Use hashing when you only need to verify a value, such as confirming a download or comparing passwords.
- Never store passwords with reversible encryption when a one way slow hash is the correct tool.
A good cryptographic hash is collision resistant, meaning it is impractical to find two inputs with the same digest.
Key idea
Encryption is reversible with a key for confidentiality, while hashing is a one way digest for integrity and verification, so choose the tool that matches whether you need to read the data again.