DevToolsForYou

Hash Generator in JavaScript / Node.js — Code Examples

Hash Generator in JavaScript / Node.jsUse the online tool →

Cryptographic hash functions convert input data into a fixed-size digest. SHA-256 is the current standard for security-sensitive use cases; MD5 is broken for security but still used for checksums.

In Node.js use the built-in crypto module. In browsers use the Web Crypto API (SubtleCrypto), which is async.

Node.js (crypto module)
const crypto = require("crypto");

// SHA-256
const sha256 = crypto.createHash("sha256")
  .update("Hello, world!")
  .digest("hex");
console.log(sha256);
// 315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3

// SHA-512
const sha512 = crypto.createHash("sha512")
  .update("Hello, world!")
  .digest("hex");

// MD5 (checksums only — not for security)
const md5 = crypto.createHash("md5")
  .update("Hello, world!")
  .digest("hex");
console.log(md5); // 6cd3556deb0da54bca060b4c39479839

// HMAC-SHA256 (for message authentication)
const hmac = crypto.createHmac("sha256", "secret-key")
  .update("Hello, world!")
  .digest("hex");
Browser (Web Crypto API)
// Web Crypto is async and only available over HTTPS
async function sha256(message) {
  const msgBuffer = new TextEncoder().encode(message);
  const hashBuffer = await crypto.subtle.digest("SHA-256", msgBuffer);
  const hashArray = Array.from(new Uint8Array(hashBuffer));
  return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
}

const hash = await sha256("Hello, world!");
console.log(hash);
Notes & gotchas
  • Web Crypto (browser) is async; Node.js crypto is synchronous.
  • MD5 is cryptographically broken — use SHA-256 or stronger for any security purpose.
  • For password hashing, use bcrypt, scrypt, or Argon2 — not SHA-256.
Try it in your browser

Need to hash md5/sha without writing code? The Hash Generator runs entirely in your browser — paste your input and get the result instantly. No signup, no install, no data sent to a server.

Open Hash MD5/SHA
Hash Generator in other languages