Hash Generator in JavaScript / Node.js — Code Examples
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.
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");// 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);- 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.
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 Python
Python's hashlib module supports MD5, SHA-1, SHA-256, SHA-512, and more with a consistent API.
Hash Generator in Go
Go's crypto package includes sha256, sha512, md5, and others. All implement the hash.Hash interface.
Hash Generator in Java
Java's java.security.MessageDigest provides MD5, SHA-1, SHA-256, and SHA-512.
Hash Generator in PHP
PHP's hash() function supports over 50 algorithms. Use hash_hmac() for HMAC authentication.
Hash Generator in Ruby
Ruby's Digest module (standard library) covers MD5, SHA-1, SHA-256, and SHA-512. For HMAC, use the OpenSSL module.
Hash Generator in Rust
Rust uses the sha2 crate for SHA-2, the md5 crate for MD5, and hmac for HMAC. The hex crate converts raw bytes to a hex string.
Hash Generator in C# / .NET
C# provides SHA256, SHA512, and MD5 in System.Security.Cryptography. .NET 5+ adds static HashData methods for one-shot hashing.