mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-19 02:51:14 +02:00
remakeEncKey
This commit is contained in:
parent
1454aff46c
commit
00562d083b
@ -32,6 +32,7 @@ export abstract class CryptoService {
|
|||||||
makeKeyPair: (key?: SymmetricCryptoKey) => Promise<[string, CipherString]>;
|
makeKeyPair: (key?: SymmetricCryptoKey) => Promise<[string, CipherString]>;
|
||||||
hashPassword: (password: string, key: SymmetricCryptoKey) => Promise<string>;
|
hashPassword: (password: string, key: SymmetricCryptoKey) => Promise<string>;
|
||||||
makeEncKey: (key: SymmetricCryptoKey) => Promise<[SymmetricCryptoKey, CipherString]>;
|
makeEncKey: (key: SymmetricCryptoKey) => Promise<[SymmetricCryptoKey, CipherString]>;
|
||||||
|
remakeEncKey: (key: SymmetricCryptoKey) => Promise<[SymmetricCryptoKey, CipherString]>
|
||||||
encrypt: (plainValue: string | ArrayBuffer, key?: SymmetricCryptoKey) => Promise<CipherString>;
|
encrypt: (plainValue: string | ArrayBuffer, key?: SymmetricCryptoKey) => Promise<CipherString>;
|
||||||
encryptToBytes: (plainValue: ArrayBuffer, key?: SymmetricCryptoKey) => Promise<ArrayBuffer>;
|
encryptToBytes: (plainValue: ArrayBuffer, key?: SymmetricCryptoKey) => Promise<ArrayBuffer>;
|
||||||
rsaEncrypt: (data: ArrayBuffer, publicKey?: ArrayBuffer, key?: SymmetricCryptoKey) => Promise<CipherString>;
|
rsaEncrypt: (data: ArrayBuffer, publicKey?: ArrayBuffer, key?: SymmetricCryptoKey) => Promise<CipherString>;
|
||||||
|
@ -318,16 +318,12 @@ export class CryptoService implements CryptoServiceAbstraction {
|
|||||||
|
|
||||||
async makeEncKey(key: SymmetricCryptoKey): Promise<[SymmetricCryptoKey, CipherString]> {
|
async makeEncKey(key: SymmetricCryptoKey): Promise<[SymmetricCryptoKey, CipherString]> {
|
||||||
const encKey = await this.cryptoFunctionService.randomBytes(64);
|
const encKey = await this.cryptoFunctionService.randomBytes(64);
|
||||||
let encKeyEnc: CipherString = null;
|
return this.buildEncKey(key, encKey);
|
||||||
if (key.key.byteLength === 32) {
|
}
|
||||||
const newKey = await this.stretchKey(key);
|
|
||||||
encKeyEnc = await this.encrypt(encKey, newKey);
|
async remakeEncKey(key: SymmetricCryptoKey): Promise<[SymmetricCryptoKey, CipherString]> {
|
||||||
} else if (key.key.byteLength === 64) {
|
const encKey = await this.getEncKey();
|
||||||
encKeyEnc = await this.encrypt(encKey, key);
|
return this.buildEncKey(key, encKey.key);
|
||||||
} else {
|
|
||||||
throw new Error('Invalid key size.');
|
|
||||||
}
|
|
||||||
return [new SymmetricCryptoKey(encKey), encKeyEnc];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async encrypt(plainValue: string | ArrayBuffer, key?: SymmetricCryptoKey): Promise<CipherString> {
|
async encrypt(plainValue: string | ArrayBuffer, key?: SymmetricCryptoKey): Promise<CipherString> {
|
||||||
@ -677,4 +673,18 @@ export class CryptoService implements CryptoServiceAbstraction {
|
|||||||
}
|
}
|
||||||
return okm;
|
return okm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async buildEncKey(key: SymmetricCryptoKey, encKey: ArrayBuffer = null)
|
||||||
|
: Promise<[SymmetricCryptoKey, CipherString]> {
|
||||||
|
let encKeyEnc: CipherString = null;
|
||||||
|
if (key.key.byteLength === 32) {
|
||||||
|
const newKey = await this.stretchKey(key);
|
||||||
|
encKeyEnc = await this.encrypt(encKey, newKey);
|
||||||
|
} else if (key.key.byteLength === 64) {
|
||||||
|
encKeyEnc = await this.encrypt(encKey, key);
|
||||||
|
} else {
|
||||||
|
throw new Error('Invalid key size.');
|
||||||
|
}
|
||||||
|
return [new SymmetricCryptoKey(encKey), encKeyEnc];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user