const iv = await Entropy.create()
const encrypted = await globalThis.crypto.subtle.encrypt({ name: 'AES-GCM', iv: iv.buffer }, encryptionKey, data[label])
const record: SafeRecord = {
- iv: iv.hex,
- salt: salt.hex,
+ iv: iv.buffer,
+ salt: salt.buffer,
label,
encrypted
}
}
const decryptionKeys: { [salt: string]: CryptoKey } = {}
for (const record of records) {
- decryptionKeys[record.salt] ??= await this.#createAesKey('decrypt', password, (await Entropy.import(record.salt)).buffer)
+ const salt = bytes.toHex(new Uint8Array(record.salt))
+ decryptionKeys[salt] ??= await this.#createAesKey('decrypt', password, record.salt)
const iv = await Entropy.import(record.iv)
- const decrypted = await globalThis.crypto.subtle.decrypt({ name: 'AES-GCM', iv: iv.buffer }, decryptionKeys[record.salt], record.encrypted)
+ const decrypted = await globalThis.crypto.subtle.decrypt({ name: 'AES-GCM', iv: iv.buffer }, decryptionKeys[salt], record.encrypted)
results[record.label] = decrypted
}
return results