1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 09:13:33 +00:00

support for prelogin kdf info

This commit is contained in:
Kyle Spearrin
2018-08-14 15:12:10 -04:00
parent a7bbdf9c93
commit 9f26f9f377
15 changed files with 140 additions and 31 deletions

View File

@@ -1,4 +1,5 @@
import { EncryptionType } from '../enums/encryptionType';
import { KdfType } from '../enums/kdfType';
import { CipherString } from '../models/domain/cipherString';
import { EncryptedObject } from '../models/domain/encryptedObject';
@@ -272,8 +273,19 @@ export class CryptoService implements CryptoServiceAbstraction {
await this.setKey(key);
}
async makeKey(password: string, salt: string): Promise<SymmetricCryptoKey> {
const key = await this.cryptoFunctionService.pbkdf2(password, salt, 'sha256', 5000);
async makeKey(password: string, salt: string, kdf: KdfType, kdfIterations: number):
Promise<SymmetricCryptoKey> {
let key: ArrayBuffer = null;
if (kdf == null || kdf === KdfType.PBKDF2) {
if (kdfIterations == null) {
kdfIterations = 5000;
} else if (kdfIterations < 5000) {
throw new Error('PBKDF2 iteration minimum is 5000.');
}
key = await this.cryptoFunctionService.pbkdf2(password, salt, 'sha256', kdfIterations);
} else {
throw new Error('Unknown Kdf.');
}
return new SymmetricCryptoKey(key);
}