Skip to content
BEAD

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/512
Python (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