Hashing
Hashing turns any data into a fixed-length string, called a hash, using a one-way function. The same input always gives the same hash, but you can't reverse it, which makes hashes useful for storing passwords and checking files.
Also called: hash, hash function, cryptographic hash, SHA-256, checksum
What is hashing?
A hash function takes input of any size, a password, a file or a whole hard drive, and produces a short, fixed-length output that acts like a fingerprint. Good cryptographic hash functions, such as the SHA-2 family in NIST's Secure Hash Standard, have three key properties:
- One-way: you can't work back from the hash to the input.
- Deterministic: the same input always produces the same hash.
- Collision-resistant: it's practically impossible to find two different inputs with the same hash, and changing even one character changes the hash completely.
Hashing vs. encryption
Encryption is two-way: with the key, you get the original data back. Hashing is one-way: there's no key and no way back. You hash data when you need to verify it, not read it again.
How hashing is used in security
- Password storage: systems store a hash of your password, not the password. At login they hash what you type and compare. NIST requires passwords to be stored with a salt and a deliberately slow hashing function, such as bcrypt, scrypt, Argon2 or PBKDF2, to resist cracking.
- File integrity: comparing a download's hash to the published one confirms it hasn't been tampered with.
- Malware detection: security tools and advisories identify known malware by file hash, see indicators of compromise.
- Digital signatures: documents and software are hashed, then the hash is signed.
Older algorithms like MD5 and SHA-1 are broken for security purposes and shouldn't be used.
Related terms
Sources
Drafted with AI assistance, then edited and fact-checked by a person. How we use AI.
