Skip to main content

What is the difference between hashing and encryption, and which do you use for passwords?

AI security · Beginner 3

Short answer

Encryption is two-way: with the key you can get the original data back. Hashing is one-way: you cannot reverse it, you can only hash a new input and compare. Passwords should be hashed, with a slow algorithm made for passwords such as Argon2 or bcrypt and a unique salt, never encrypted or stored as plain text.

Deeper answer

Use encryption when you need the data back later, such as a scanned ID document stored for KYC, or data in transit with TLS. Its safety depends on protecting the key. Use hashing when you only need to check a value matches, such as a password or a file's integrity.

Fast hashes like SHA-256 are good for checking files but poor for passwords, because attackers can try billions of guesses quickly. Password hashing algorithms are deliberately slow and take a salt, a random value per user, so two users with the same password get different hashes and precomputed tables do not work. Never invent your own scheme; use a maintained library.

What a strong answer covers

Answer it out loud in the mock interview about 1.5 min

Follow-ups to expect

Common mistakes

Learn it

Cryptography basics

Practice AI security questions

More on this topic

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.