Building a Hash Generator with Web Crypto API and a Pure-JS MD5 Fallback
Every developer runs into hashing at some point. Checking file integrity, storing password fingerprints, verifying API payloads, generating cache keys. Most reach for a CLI tool (shasum, md5sum) or...

Source: DEV Community
Every developer runs into hashing at some point. Checking file integrity, storing password fingerprints, verifying API payloads, generating cache keys. Most reach for a CLI tool (shasum, md5sum) or an npm package. But what if you could hash text and files directly in the browser — no installs, no dependencies, no server? I built a Hash Generator that supports MD5, SHA-1, SHA-256, SHA-384, and SHA-512. All client-side. Here's how it works under the hood. The Web Crypto API Does Most of the Work Modern browsers ship with crypto.subtle — a native cryptographic API that handles SHA algorithms with hardware-accelerated performance. async function computeHash( data: Uint8Array, algorithm: Algorithm ): Promise<string> { if (algorithm === "MD5") return md5(data); const hashBuffer = await crypto.subtle.digest(algorithm, data); return Array.from(new Uint8Array(hashBuffer)) .map(b => b.toString(16).padStart(2, "0")) .join(""); } That's it for SHA-1, SHA-256, SHA-384, and SHA-512. crypto.