Hash generator

Type or paste text to see its MD5, SHA-1, SHA-256, SHA-384 and SHA-512 hashes at once.

This tool runs in your browser. We never send what you type or paste to a server.

Which hash should I use?

  • SHA-256 is the safe default for checksums, signatures and content addressing.
  • MD5 and SHA-1 are broken for security (collisions can be manufactured) but still fine for non-security checksums and cache keys.
  • For passwords, never use a plain hash. Use a slow, salted password hash such as Argon2, bcrypt or scrypt.

Details

Text is hashed as UTF-8 bytes, so results match sha256sum, openssl dgst and most programming languages for the same input. Watch out for trailing newlines: echo "hi" | sha256sum hashes "hi\n", not "hi". Use echo -n.

Example

The text hello (no newline) hashes to:

MD5      5d41402abc4b2a76b9719d911017c592
SHA-1    aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
SHA-256  2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

If your result differs from echo hello | sha256sum, that is because echo adds a newline. Use printf hello instead.

What the output tells you

A hash function turns input of any length into a fixed-length number, shown here in hexadecimal, two characters per byte. The length alone tells you which algorithm made a hash:

MD5      128 bits   32 hex characters
SHA-1    160 bits   40
SHA-256  256 bits   64
SHA-384  384 bits   96
SHA-512  512 bits  128

Change one character and the whole result changes, with no visible relation to the old one. hello and Hello share nothing:

hello  2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Hello  185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969

One value worth recognising: e3b0c442…b855 is the SHA-256 of empty input. If a script or log shows it, the thing you meant to hash was empty, often a file that failed to download or a variable that was never set. Upper and lower case hex mean the same; tick Uppercase to match tools such as PowerShell's Get-FileHash.

Hashing a string in JavaScript

In Node, crypto.createHash covers every algorithm here, including MD5, and can output hex or Base64:

import { createHash, createHmac } from 'node:crypto';
console.log(createHash('sha256').update('hello').digest('hex'));   // → 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
console.log(createHash('sha256').update('Hello').digest('hex'));   // → 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969
console.log(createHash('md5').update('hello').digest('hex'));      // → 5d41402abc4b2a76b9719d911017c592
console.log(createHash('sha384').update('hello').digest('base64'));   // → WeF0h3dEjGnea4ANejO7+5/xtGPkQ1TDVTvNucZm+pASWjx5+QOXvfX2oT3oKGhP

In the browser, the Web Crypto API does SHA-1, SHA-256, SHA-384 and SHA-512 but not MD5 (this tool adds its own MD5). It is asynchronous, works only on HTTPS pages and localhost, and returns bytes that you convert to hex yourself:

// crypto.subtle works in browsers (HTTPS or localhost only) and in Node 19+.
const bytes = new TextEncoder().encode('hello');
const digest = await crypto.subtle.digest('SHA-256', bytes);
const hex = [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, '0')).join('');
console.log(hex);                                                   // → 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Python, the shell and PowerShell

Python's hashlib hashes bytes, so encode text first:

import hashlib, hmac
print(hashlib.sha256('hello'.encode('utf-8')).hexdigest())   # → 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
print(hashlib.md5(b'hello').hexdigest())                     # → 5d41402abc4b2a76b9719d911017c592
print(hashlib.sha256(b'').hexdigest())                       # → e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855   empty input
print(hmac.new(b'secret-key', b'hello', hashlib.sha256).hexdigest())   # → 98e7ffb964bb5a3f902db1fc101a5baa98b6f2cd56858210c9d70f26ac762fc7

On the command line, the classic mistakes are the newline that echo adds and the carriage return that Windows editors add to every line. Both change the hash completely:

printf 'hello' | sha256sum | cut -d' ' -f1       # → 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
echo 'hello' | sha256sum | cut -d' ' -f1         # → 5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03   hashes hello plus a newline
printf 'hello\r\n' | sha256sum | cut -d' ' -f1   # → cd2eca3535741f27a8ae40c31b0c41d4057a7a7b912b33b9aed86485d1c84676   Windows line ending
printf 'hello' | openssl dgst -sha256 -hmac 'secret-key' | cut -d' ' -f2   # → 98e7ffb964bb5a3f902db1fc101a5baa98b6f2cd56858210c9d70f26ac762fc7

Windows PowerShell's Get-FileHash also hashes a stream, which lets it hash a string; it prints upper-case hex:

$bytes = [Text.Encoding]::UTF8.GetBytes('hello')
$hash = Get-FileHash -Algorithm SHA256 -InputStream ([IO.MemoryStream]::new($bytes))
$hash.Hash                       # → 2CF24DBA5FB0A30E26E83B2AC5B9E29E1B161E5C1FA7425E73043362938B9824
$hash.Hash.ToLower()             # → 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Hashing files, and the hashes in your HTML

This tool hashes text you type, not files. To check a download against a published checksum, hash the file itself, in binary mode and in blocks so a large file does not fill memory:

def file_sha256(path):
    h = hashlib.sha256()
    with open(path, 'rb') as f:                  # binary mode: no newline translation
        for block in iter(lambda: f.read(1 << 16), b''):
            h.update(block)
    return h.hexdigest()
sha256sum ubuntu.iso                     # Linux, Git Bash
shasum -a 256 ubuntu.iso                 # macOS
certutil -hashfile ubuntu.iso SHA256     # Windows cmd
Get-FileHash ubuntu.iso                  # PowerShell, SHA-256 by default

Subresource Integrity, the integrity="sha384-…" attribute on script and link tags, uses the same hash written in Base64 rather than hex, so a hex digest from this page will not fit there. Produce it from the file's bytes:

printf 'hello' | openssl dgst -sha384 -binary | base64 -w 0; echo   # → WeF0h3dEjGnea4ANejO7+5/xtGPkQ1TDVTvNucZm+pASWjx5+QOXvfX2oT3oKGhP

Hash or HMAC?

To prove that a message came from someone who knows a secret, as webhook signatures and API request signing do, use an HMAC, not sha256(secret + message). Plain SHA-256 and SHA-512 allow length-extension attacks on that construction; HMAC (RFC 2104) does not. Compare signatures with a constant-time function such as crypto.timingSafeEqual or hmac.compare_digest.

console.log(createHmac('sha256', 'secret-key').update('hello').digest('hex'));   // → 98e7ffb964bb5a3f902db1fc101a5baa98b6f2cd56858210c9d70f26ac762fc7

Questions

Can a hash be reversed?

No. Hashes are one-way. Short or common inputs can be guessed with lookup tables, which is why passwords need slow, salted hashing.

Why doesn't my hash match the command line?

Usually a trailing newline or different encoding. Use echo -n, and make sure the text is UTF-8.

Should I use MD5 or SHA-1 for passwords?

No. They are fine for checksums and cache keys but far too fast for passwords. Use a password hashing function such as Argon2, bcrypt or scrypt.

How do I get the SHA-256 of a string in JavaScript?

In Node: require or import createHash from node:crypto and call createHash('sha256').update(text).digest('hex'). In the browser: encode the text with TextEncoder, await crypto.subtle.digest('SHA-256', bytes) and convert the resulting bytes to hex.

What is the SHA-256 of an empty string?

e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855. Seeing it usually means the input was empty by mistake.

Can I hash a file with this tool?

No, it hashes text. Use sha256sum or shasum -a 256 on Linux and macOS, Get-FileHash in PowerShell, or certutil -hashfile in the Windows command prompt.

Why is my hash in upper case in one tool and lower case in another?

Hex digits are case-insensitive, so both are the same hash. Convert one before comparing strings, or tick Uppercase here.