Last active
July 17, 2025 16:40
-
-
Save allenhwkim/2be4bebe1f08cf5c149a326a4bb0aba3 to your computer and use it in GitHub Desktop.
Create md5 hash from string in browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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