Skip to content

Instantly share code, notes, and snippets.

@iwstkhr
Created October 31, 2023 13:32
Show Gist options
  • Save iwstkhr/d2cbfa5fd1f65809aac253edd113d1a7 to your computer and use it in GitHub Desktop.
Save iwstkhr/d2cbfa5fd1f65809aac253edd113d1a7 to your computer and use it in GitHub Desktop.
Generating Hash Values from Texts
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