Use PBKDF for pwd-box
This commit is contained in:
+2
-20
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user