Hashing Snippet Generator
MD5 / SHA-1 / SHA-256 / SHA-512 / HMAC-SHA256 snippets in Node, browser, Python, PHP, Ruby, Go, Rust, and shell.
Node.js (crypto)
import { createHash } from "node:crypto";
const hash = createHash("sha256").update("hello world").digest("hex");
console.log(hash);Browser (Web Crypto)
const data = new TextEncoder().encode("hello world");
const buf = await crypto.subtle.digest("SHA-256", data);
const hex = Array.from(new Uint8Array(buf)).map(b => b.toString(16).padStart(2, "0")).join("");
console.log(hex); // browser has no built-in MD5 / SHA-1 hex helper — this works for SHA-256/512Python (hashlib / hmac)
import hashlib
print(hashlib.sha256("hello world".encode()).hexdigest())PHP
<?php
echo hash("sha256", "hello world");Ruby (OpenSSL::Digest)
require "digest"
puts Digest::SHA256.hexdigest("hello world")Go (crypto/...)
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
)
func main() {
sum := sha256.Sum256([]byte("hello world"))
fmt.Println(hex.EncodeToString(sum[:]))
}Rust (sha2 / hmac)
// Cargo: sha2 = "...", hex = "0.4"
use sha2::{Digest, Sha256};
fn main() {
let mut hasher = Sha256::new();
hasher.update("hello world".as_bytes());
println!("{}", hex::encode(hasher.finalize()));
}Shell (openssl)
printf %s 'hello world' | sha256sum
What you get
Pick an algorithm (MD5, SHA-1, SHA-256, SHA-512, or HMAC-SHA256) and copy the equivalent snippet in eight languages — Node, browser, Python, PHP, Ruby, Go, Rust, and shell.
HMAC
For HMAC variants, the secret key field is interpolated into each snippet alongside the message. Keep secrets out of code in production — these snippets are for prototyping or doc copy.
You might also like
- UUID v3 / v5 (namespace)Generate deterministic UUIDs from a namespace + name. Standard DNS / URL / OID / X.500 namespaces built in.
- .gitignore BuilderPick languages, frameworks, build tools, editors and OS — get a deduped .gitignore.
- .gitignore GeneratorBuild a .gitignore by picking from common language, framework, and OS templates.
- Dockerfile StarterMulti-stage Dockerfiles for Node, Python, PHP, Go, Ruby, Rust, Java, and static sites — plus matching .dockerignore.