Use PBKDF for pwd-box

This commit is contained in:
2024-05-15 12:13:58 +02:00
parent b0e34f3716
commit 267f6737fa
+2 -20
View File
@@ -1,6 +1,7 @@
import {Result} from 'result'
import * as misc from 'misc'
import {SecretBox} from './symmetric'
import {pbkdf} from '../pbkdf'
export class PwdBox<T> {
private readonly secret_box: SecretBox<T>
@@ -25,26 +26,7 @@ export class PwdBox<T> {
}
private static async gen_key(pwd: string, salt: Uint8Array) : Promise<CryptoKey> {
const keyMaterial = await window.crypto.subtle.importKey(
"raw",
new TextEncoder().encode(pwd),
"PBKDF2",
false,
["deriveBits", "deriveKey"],
)
return crypto.subtle.deriveKey(
{
name: "PBKDF2",
iterations: 250_000,
hash: "SHA-512",
salt,
},
keyMaterial,
{name: "AES-GCM", length: 256},
false,
["encrypt", "decrypt"],
)
return pbkdf(pwd, salt, ["encrypt", "decrypt"])
}
public toString() : string {