Hash Functions Explained: MD5, SHA-256, and One-Way Security
DDEVELOPER
DeveloperPublished: 4 min read

Hash Functions Explained: MD5, SHA-256, and One-Way Security

A hash function such as SHA-256 turns input data into a fixed-length digest. Unlike encryption, it has no decryption key. But that does not mean a hash prevents someone from guessing the input. To understand what ‘one-way’ means, first separate what an attacker is given from what they are trying to find.

Japanese original published: 2026-05-07

Preimage, second-preimage, and collision resistance

These three security properties describe different tasks:

  • Preimage resistance: given a digest, it should be difficult to find an input that produces it.
  • Second-preimage resistance: given one input, it should be difficult to find a different input with the same digest.
  • Collision resistance: it should be difficult to find any two different inputs with the same digest. The attacker can choose both inputs.

Finding a collision gives the attacker more freedom than matching a particular digest. Even for an ideal n-bit hash, the birthday effect puts generic collision search on the order of 2^(n/2) trials. This is a scale estimate, not a guaranteed number of attempts or a measure of every possible attack. The actual strength depends on the algorithm, input length, and attack model.

A short digest does not make a short secret hard to guess

There are more possible long inputs than fixed-length digests, so some different inputs must share a digest. That fact does not prove that finding an input for a particular digest is easy—or hard. Likewise, the avalanche effect, where a small input change changes many output bits, does not by itself prove one-way security.

A four-digit PIN has only 10,000 possible values. An attacker can hash each candidate and compare the result. This can reveal a guessable input without breaking the hash algorithm.

For password storage, use a dedicated password hashing scheme with a salt and a configurable cost factor. Do not store a plain MD5 or SHA digest as the password verifier. NIST’s password-verifier guidance describes salted password hashing and a cost factor that makes each guess more expensive.

MD5 and SHA-1 collisions are not hash decryption

RFC 6151 rules out MD5 where collision resistance is required, including digital signatures. The SHAttered research also demonstrated two different PDF files with the same SHA-1 digest. Neither result was an experiment that recovered the original data from an arbitrary digest. Conversely, difficulty finding a preimage does not make an old signature scheme safe when collision attacks undermine it.

SHA-256, SHA-384, and SHA-512 belong to the SHA-2 family. SHA-384 uses different initial values and a different final output from SHA-512: it is not simply a SHA-512 digest with its end removed. SHA-3 is a separately designed family defined in FIPS 202. NanToo’s hash generator does not implement SHA-3.

Choose an algorithm for the requirements of the application or protocol, rather than treating the largest number in its name as a universal recommendation.

Compare the same bytes, not just similar-looking text

Hashes operate on bytes. The hash generator encodes the text field as UTF-8. It does not trim spaces or apply Unicode normalization, and line breaks in the text field use LF. This is a text-hashing tool, not a file-checksum tool.

SHA-256("hello") = 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

To reproduce this example, enter hello without the quotation marks and without a trailing newline. Different spaces, line endings, or Unicode sequences can produce different bytes and therefore different hashes. The UTF-8 guide explains why character counts and byte counts are different.

Lowercase hexadecimal, uppercase hexadecimal, and Base64 can represent the same digest bytes; they do not change the algorithm. See the Base64 and Base64url guide for the distinction between an encoding and the data it represents.

A matching digest does not, by itself, prove who sent the data. To guard against malicious changes, use an expected digest obtained through a trusted channel, a digital signature, or an authentication mechanism appropriate to the application.

References and sources

Editorial note

This article was prepared with AI assistance and reviewed by an editor before publication. It may still contain factual errors, interpretation mistakes, or outdated information. Check the cited primary sources or official documentation before making an important decision.

Related tools

Related articles