mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-14 01:10:54 +03:00
8 lines
450 B
TypeScript
8 lines
450 B
TypeScript
|
|
export async function createSHA256hash(input: string) {
|
||
|
|
const msgUint8 = new TextEncoder().encode(input); // encode as (utf-8) Uint8Array
|
||
|
|
const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8); // hash the message
|
||
|
|
const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
|
||
|
|
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string
|
||
|
|
return hashHex;
|
||
|
|
}
|