The big difference: encryption can be reversed with the right key. Hashing can't. It's one-way.
That one difference decides what each one is used for.
Encryption: for confidentiality
Encryption scrambles data so only someone with the key can read it. You use it when you need to get the original data back, like sending a file or storing a credit card number.
Hashing: for integrity
A hash turns data into a fixed-length fingerprint. Change even one character and the hash changes completely. You can't turn a hash back into the original data.
That makes it great for checking that something hasn't changed, like comparing the hash of a download, or verifying a forensic disk image hasn't been altered.
Hashing passwords
Systems shouldn't store your actual password. They store a hash of it. When you log in, they hash what you typed and compare.
Salting adds a random value to each password before hashing it. That way two people with the same password get different hashes, and precomputed attacks like rainbow tables don't work. Slow hashing functions built for passwords, like PBKDF2, make cracking even harder.
Which to use
- Need to read the data again later? Encrypt it
- Need to prove it hasn't changed, or store a password? Hash it
Cheat sheet
- Encryption is reversible with a key
- Hashing is one-way
- Encryption = confidentiality, hashing = integrity
- Store password hashes, not passwords
- Salting stops identical passwords from matching and defeats rainbow tables
Common questions
Can a hash be decrypted?
No. Hashing is one-way, so there's no key to reverse it.
What is salting a password?
Adding a random value to each password before hashing, so identical passwords get different hashes.
Is hashing used for confidentiality or integrity?
Integrity. It proves data hasn't changed.
Studying for Security+?
Security+ Practice Test 701 has 1,100 practice questions with clear explanations, so you know why every answer is right.