Created
October 31, 2023 13:32
-
-
Save iwstkhr/d2cbfa5fd1f65809aac253edd113d1a7 to your computer and use it in GitHub Desktop.
Generating Hash Values from Texts
This file contains 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
export async function getHashByUrl(url: string): Promise<string> { | |
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest | |
const uint8 = new TextEncoder().encode(url); | |
const digest = await crypto.subtle.digest('SHA-256', uint8); | |
return Array.from(new Uint8Array(digest)).map(b => b.toString(16).padStart(2,'0')).join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment