Implement PBKDF

Closes #12
This commit is contained in:
2024-05-15 12:12:33 +02:00
parent 0347f30bd0
commit b0e34f3716
3 changed files with 41 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
export async function pbkdf(password: string, salt: Uint8Array, usages: KeyUsage[]): Promise<CryptoKey> {
const keyMaterial = await window.crypto.subtle.importKey(
"raw",
new TextEncoder().encode(password),
"PBKDF2",
false,
["deriveBits", "deriveKey"],
)
return crypto.subtle.deriveKey(
{
name: "PBKDF2",
iterations: 250_000,
hash: "SHA-512",
salt,
},
keyMaterial,
{name: "AES-GCM", length: 256},
false,
usages,
)
}