Encryption vs Hashing: What's the difference?
Encryption is reversible with the correct key, while hashing is designed to produce a one-way digest of data.
Encryption
Encryption transforms plaintext into ciphertext so authorized parties can recover the original data with the appropriate key.
Hashing
A cryptographic hash converts input into a fixed-size digest and is designed to make recovery of the original input impractical.
Key differences between Encryption and Hashing
| Decision factor | Encryption | Hashing |
|---|---|---|
| Reversibility | Designed to be reversible with the correct key. | Designed as a one-way transformation with no decryption key. |
| Primary goal | Protect confidentiality of data at rest or in transit. | Verify integrity, derive identifiers or support secure password verification with a suitable password-hashing function. |
| Key material | Uses cryptographic keys that must be protected and managed. | General hashes use no secret key; password hashing adds salt and work factors, while HMAC uses a key for authentication. |
Choose Encryption if
Use encryption when data must remain confidential but later be recovered by authorized users or systems.
Choose Hashing if
Use hashing for integrity checks and, with a proper password-hashing function, for password verification.
Practical example
A database field containing a recovery secret may need encryption because the application must later recover the original value. User passwords should instead be stored with a slow password-hashing algorithm such as Argon2id, bcrypt or scrypt so the original password is not recoverable from storage.
Can you use Encryption and Hashing together?
Systems often use both. TLS encrypts network traffic, while hashes verify downloaded file integrity. Encrypted backups may also store checksums. The algorithms and key-management requirements are different, so choose each primitive for its intended security property.
Common mistake to avoid
Do not store passwords with reversible encryption merely because it is “secure.” A breach of the encryption key exposes every password. Use a dedicated salted password-hashing function with an appropriate work factor. Also avoid obsolete hashes such as MD5 or SHA-1 for security-sensitive integrity.
Key takeaway
Do not treat hashing as encryption or store passwords with reversible encryption when a password-hashing function is the correct control.
Frequently asked questions
Can a cryptographic hash be decrypted?
No. A hash is not encryption and has no decryption key. Attackers can still guess inputs and compare hashes, which is why password hashing must be deliberately slow and salted.
Should I hash or encrypt files?
Encrypt when confidentiality is required. Hash when you need to verify that content has not changed. Many workflows use both.
Is SHA-256 suitable for storing passwords directly?
Not by itself. Use a password-hashing or key-derivation algorithm designed to resist brute-force attacks, with a unique salt and suitable cost parameters.