Skip to content

Instantly share code, notes, and snippets.

@bilelz
Last active December 1, 2022 13:21
Show Gist options
  • Save bilelz/c96fb0b1f62983d061910e8d310a5162 to your computer and use it in GitHub Desktop.
Save bilelz/c96fb0b1f62983d061910e8d310a5162 to your computer and use it in GitHub Desktop.
generate Checksum (Sha256) from a blob or a file (vanillajs)
async function getChecksumSha256(blob: Blob): Promise<string> {
const uint8Array = new Uint8Array(await blob.arrayBuffer());
const hashBuffer = await crypto.subtle.digest('SHA-256', uint8Array);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map((h) => h.toString(16).padStart(2, '0')).join('');
// if you like, it, yan can buy me a coffee https://paypal.me/bilelz/1000000
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment