Created
June 25, 2024 03:21
-
-
Save mattrossman/b299fc7f2774cce0a6d5f6234aba5374 to your computer and use it in GitHub Desktop.
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 generateRandomSHA1Hash() { | |
const data = crypto.getRandomValues(new Uint8Array(16)) | |
const hashBuffer = await crypto.subtle.digest("SHA-1", data) | |
const hashArray = Array.from(new Uint8Array(hashBuffer)) | |
const hashHex = hashArray | |
.map((byte) => byte.toString(16).padStart(2, "0")) | |
.join("") | |
return hashHex | |
} | |
export async function generateSHA1Hash(input: string) { | |
const encoder = new TextEncoder() | |
const data = encoder.encode(input) | |
const hashBuffer = await crypto.subtle.digest("SHA-1", data) | |
const hashArray = Array.from(new Uint8Array(hashBuffer)) | |
const hashHex = hashArray | |
.map((byte) => byte.toString(16).padStart(2, "0")) | |
.join("") | |
return hashHex | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment