Hash Generator: how it works and how to build one
MD5, SHA-1, SHA-256, SHA-384 and SHA-512 of text or files. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Type text or drop a file to get all common hashes at once. Use it to check a download against its published checksum, generate cache keys, or compare two files without opening them.
When to use it
- Checking a downloaded file matches its published checksum
- Cache keys
- Comparing files without opening them
How to use it
- Type or paste text, or open a file.
- All hashes update as you type.
- Paste a checksum into Compare to check it matches.
Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/hash-generator
How it works
A hash function turns any input into a fixed-length fingerprint. Change one letter and the hash changes completely. The browser’s Web Crypto API (crypto.subtle.digest) computes SHA-1, SHA-256, SHA-384 and SHA-512 natively and fast.
MD5 is not in Web Crypto because it is broken for security, but it is still used for checksums, so it needs a small JavaScript implementation.
Build it yourself
Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.
hash.ts (ts)
export async function sha(algo: "SHA-1" | "SHA-256" | "SHA-384" | "SHA-512", data: string | ArrayBuffer) {
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
const digest = await crypto.subtle.digest(algo, bytes);
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
}
// For a file: await sha("SHA-256", await file.arrayBuffer());
Make it production-ready
- Add HMAC with crypto.subtle.importKey and sign.
- Let users paste an expected hash and highlight a match.
Questions
Should I hash passwords with SHA-256?
No. Use a slow password hash such as bcrypt or Argon2 on your server. SHA hashes are fast, which makes them easy to brute force.
Is MD5 still useful?
For checksums and cache keys, yes. For security, no.
Free, runs in your browser, nothing is uploaded.