ScienceComputer Science

Hash
generator.

Get the SHA-256, SHA-512 or MD5 fingerprint of text or a file, worked out on your device.

How it's worked out

A hash function reads any number of bytes and returns a digest of fixed length: 256 bits for SHA-256, 512 for SHA-512 and 128 for MD5. The same bytes always give the same digest. A different input almost always gives a completely different one.

FIPS 180-4 defines the SHA family. SHA-256 first pads the message: it adds a single 1 bit, then 0 bits, then the message length as a 64-bit number, so the total is a multiple of 512 bits. Each 512-bit block is then mixed into eight 32-bit words over 64 rounds. The words start at fixed values taken from the square roots of the first eight primes.

ℓ+1+k\displaystyle \ell + 1 + k≡448(mod512)\displaystyle {}\equiv 448 \pmod{512}

Here ℓ\ell is the message length in bits and kk is the number of zero bits added. Text is first turned into bytes as UTF-8, so an accented letter is two bytes and an emoji is four.

This page hashes in your browser. SHA-256 and MD5 run in the page itself; SHA-1, SHA-384, SHA-512 and HMAC use the browser's built-in Web Crypto. Your text, file and key are not sent anywhere, and nothing is saved on the device. A share link carries the text in the part of the address after #, which the browser does not send to the server, and it never carries the key.

Worked examples

Zoe gets a different SHA-256 in her terminal

Zoe hashes the word foobar here and gets c3ab8ff13720e8ad…. In a terminal, echo foobar piped to sha256sum gives aec070645fe53ee3….

The terminal is not wrong. echo adds a newline, so it hashed seven bytes, not six. Typing foobar and a line break in the box gives the terminal's value. Using printf or echo -n leaves the newline out and gives the first value.

Open this example in the tool

Omar tests his own SHA-256 code with the standard test text

FIPS 180-4 pads the three-byte message abc into a single 512-bit block, as its own example shows. Its SHA-256, shown here in groups of eight, is ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad.

Omar's code should give exactly those 64 hex digits. If it does not, the padding or the byte order is the usual culprit. RFC 1321 lists the MD5 of the same text as 90015098 3cd24fb0 d6963f7d 28e17f72, and that is what the tool shows for MD5.

Open this example in the tool

Ines changes one letter and watches the digest change

The SHA-256 of Hello, world starts 4ae7c3b6ac0beff6. Ines changes the last letter to get Hello, worle. The new digest starts 92d905a3ce0ea87b.

133 of the 256 bits changed, close to half, though only one bit of the input changed. That spread, called the avalanche effect, is why a digest gives no hint of how close two inputs are. In Base64, the first digest is 44 characters long and starts SufDtqwL7/Zx76jP.

Open this example in the tool

Reading your result

Hex or Base64. Both show the same bits. Hex uses two characters per byte, so SHA-256 is 64 characters. Base64 uses about four characters per three bytes, so SHA-256 is 44 characters with one = on the end. Use whichever form the other side prints.

Checking a download. Paste the hash the publisher prints into the check box. A match means the file you have is byte for byte the one they hashed. It only proves the file is genuine if you got the hash from a source you trust, such as the project's own site over HTTPS.

Which algorithm. The SHA-2 family, SHA-256, SHA-384 and SHA-512, is current. NIST says SHA-1 should be phased out by Dec. 31, 2030, because collisions can now be made on purpose. RFC 6151 says MD5 is no longer acceptable where collision resistance is needed, such as digital signatures. Both still catch accidental damage.

Even empty input has a digest. The SHA-256 of no bytes at all is e3b0c44298fc1c14…. If you see that value, the file or text was empty.

Common mistakes

  • A line ending you cannot see. Hello, world gives 4ae7c3b6ac0beff6…. With a Unix newline it is 37980c33951de6b0…, and with a Windows line ending it is 701e802eb2e17311….
  • A change in case. Hello, World with a capital W gives 03675ac53ff9cd15…. Hashes match only when every byte matches.
  • Comparing different algorithms. In hex, a 32-character value is MD5, 40 is SHA-1, 64 is SHA-256 and 128 is SHA-512. The check box says which length it found.
  • Storing passwords as a plain hash. OWASP says fast hashes such as SHA-256 are not suitable for password storage. Use Argon2id, scrypt, bcrypt or PBKDF2.
  • Treating a hash as a signature. Anyone can hash a file. To show a message came from someone who holds a secret, use HMAC with a key, or a digital signature.

Questions people ask

echo adds a newline to the end, so the command hashes one more byte than you typed. Use printf with %s, or echo -n, to hash the text alone. Windows tools may add a carriage return as well, which changes the hash again.

Sources