← Guides

Developer Guide

Hash Generation in JavaScript

SHA-256 in the browser with Web Crypto (https or localhost) and in Node with createHash. Hex versus Base64 digests. MD5 is not in Web Crypto or this site’s Hash Generator — and SHA-256 is not for passwords.

web crypto sha-256createHash sha256 hexhmac sha-256 javascriptmd5 not web cryptohash digest base64

JavaScript can hash strings and files in the browser with the Web Crypto API, and on the server with the Node.js crypto module. crypto.subtle.digest is async and requires a secure context (https or localhost). crypto.createHash('sha256').update(data, 'utf8').digest('hex') is the Node one-liner. Both speak SHA-256, SHA-384, and SHA-512. Web Crypto also offers SHA-1; it does not offer MD5.

/tools/hash-generator matches that set: SHA-1, SHA-256, SHA-384, SHA-512, and optional HMAC, from pasted text or a local file. There is no MD5 button. SHA-256 of hello is 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824. That hex is a checksum, not a way to store passwords — use a slow KDF (Argon2id, bcrypt, scrypt) for that, and /tools/password-generator only to mint a secret.

Browser: SHA-256 with Web Crypto

Encode the string with TextEncoder, digest it as SHA-256, then map the ArrayBuffer to hex. The call is a Promise. On insecure HTTP (not localhost) crypto.subtle is missing and the await will fail — serve https, or hash in Node.

/tools/hash-generator is the same Web Crypto path: pick SHA-256, paste hello, read 64 lowercase hex characters. Toggle uppercase if a manifest uses A–F.

async function sha256hex(text) {
  const data = new TextEncoder().encode(text);
  const buf = await crypto.subtle.digest('SHA-256', data);
  return [...new Uint8Array(buf)]
    .map((b) => b.toString(16).padStart(2, '0'))
    .join('');
}

await sha256hex('hello');
// '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'

Node.js: crypto.createHash

Node can be synchronous: createHash('sha256').update(data, 'utf8').digest('hex'). Stream a file with hash.update(chunk) and hash.digest('hex') at the end. Algorithm names are lowercase (sha256, sha384, sha512, sha1).

MD5 still exists on createHash('md5') for legacy checksums you are forced to match. Do not use it in new code, do not use it for passwords, and do not expect /tools/hash-generator to reproduce it — the site omits MD5 on purpose.

import { createHash } from 'node:crypto';

createHash('sha256').update('hello', 'utf8').digest('hex');
// '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'

createHash('sha256').update('hello', 'utf8').digest('base64');
// 'LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ='

Hex versus Base64 output

A SHA-256 digest is 32 bytes. Hex writes two characters per byte (64 chars). Base64 writes those same bytes in the Base64 alphabet (LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ= for hello). Hex is the usual display format in manifests; Base64 shows up in headers.

In the browser, hex-map the Uint8Array as above, or Base64-encode the bytes. A digest cannot be reversed. /tools/encryption-decryption is the tool for ciphers you can decrypt.

HMAC

HMAC mixes a secret key with the message. It answers “did someone who knows this key produce this digest?” not “are these the same bytes?” Enable HMAC on /tools/hash-generator, paste the key, hash the message. The secret stays in the tab.

RFC 4231 test case 2: key Jefe, message what do ya want for nothing?, HMAC-SHA-256 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843. Node: createHmac('sha256', 'Jefe').update('what do ya want for nothing?').digest('hex'). HMAC is still fast — it is not a password KDF.

MD5 is not here, and SHA-256 is not for passwords

Web Crypto does not expose MD5. This site’s Hash Generator does not either. MD5 is collision-broken and too often pasted into password columns. If a vendor only publishes MD5, look for SHA-256 from a second channel.

Do not store SHA-256(password). SHA-256 is fast on purpose. A unique salt does not make it slow enough. Password storage needs Argon2id, bcrypt, or scrypt with a per-user salt. Mint the secret with /tools/password-generator; hash it in your application with a password KDF. The Hash Generator is a checksum and HMAC workbench.

Common pitfalls

Calling digest in an insecure HTTP context and treating a missing subtle as a browser bug. Hashing a typed filename instead of file bytes. Comparing hex with different case. Using JSON.stringify as HMAC input without sorting keys.

Hashing in the browser does not hide input from XSS. Do not copy SHA-256 hex from /tools/hash-generator into a user table.

  • subtle.digest needs https or localhost and returns a Promise.
  • SHA-256(hello) hex is 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824.
  • No MD5 in Web Crypto or /tools/hash-generator. Never SHA-256 passwords.

Worked examples

SHA-256 of hello (hex)

Input
hello
Output
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Web Crypto, Node createHash('sha256'), and /tools/hash-generator on SHA-256 all agree.

SHA-256 of hello (Base64)

Input
createHash('sha256').update('hello', 'utf8').digest('base64')
Output
LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=

Same 32 bytes as the hex form. The Hash Generator displays hex; convert if a header wants Base64.

HMAC-SHA-256 (RFC 4231 test case 2)

Input
key Jefe · message what do ya want for nothing?
Output
5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843

Enable HMAC on /tools/hash-generator with the same key. This authenticates only while Jefe stays secret.

Frequently asked questions

Why is crypto.subtle undefined?

Web Crypto’s subtle API is available on https pages and on localhost. Plain HTTP on a LAN hostname will not hash in the browser. Use Node, or serve TLS.

Can I hash passwords with SHA-256?

No. SHA-256 is a fast checksum. Store passwords with Argon2id, bcrypt, or scrypt. /tools/hash-generator is not a KDF.

Where is MD5?

Not in Web Crypto, and not in /tools/hash-generator. Node still has createHash('md5') for legacy checksums you must match. Do not use it for security.

Hex or Base64?

Hex (64 characters for SHA-256) is what manifests and this site’s generator show. Base64 is shorter for headers. They are the same digest bytes.

Does the Hash Generator upload my file?

No. Text and dropped files are digested with Web Crypto in the tab. HMAC keys stay there too.

Summary

Use crypto.subtle.digest in a secure context or createHash('sha256').update(data, 'utf8').digest('hex') in Node, encode the 32 bytes as hex or Base64, and reserve HMAC for a shared key. Confirm hello → 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 on /tools/hash-generator. Skip MD5, and do not store passwords as SHA-256.

Try it yourself

Put what you've learned into practice with our free browser-native tool.

Open Tool →