Skip to content

Instantly share code, notes, and snippets.

@allenhwkim
Last active July 17, 2025 16:40
Show Gist options
  • Save allenhwkim/2be4bebe1f08cf5c149a326a4bb0aba3 to your computer and use it in GitHub Desktop.
Save allenhwkim/2be4bebe1f08cf5c149a326a4bb0aba3 to your computer and use it in GitHub Desktop.
Create md5 hash from string in browser
async function hashString(str) {
const data = new TextEncoder().encode(str);
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
return Array.from(new Uint8Array(hashBuffer)).map(b => b.toString(16).padStart(2, '0')).join('');
}
const hash1 = await hashString(string1);
const hash2 = await hashString(string2);
if (hash1 === hash2) {
console.log("Strings are equal");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment