mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 14:53:33 +00:00
[PM-3732] Use subtle to make aes keys (#6162)
* Provide `aesGenerateKey` to make aes keys * Use aesGenerateKey when generating a key data * Fix device test
This commit is contained in:
@@ -271,6 +271,15 @@ describe("NodeCrypto Function Service", () => {
|
||||
).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("aesGenerateKey", () => {
|
||||
it("should delegate to randomBytes", async () => {
|
||||
const nodeCryptoFunctionService = new NodeCryptoFunctionService();
|
||||
const spy = jest.spyOn(nodeCryptoFunctionService, "randomBytes");
|
||||
await nodeCryptoFunctionService.aesGenerateKey(256);
|
||||
expect(spy).toHaveBeenCalledWith(32);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function testPbkdf2(
|
||||
|
||||
@@ -271,6 +271,10 @@ export class NodeCryptoFunctionService implements CryptoFunctionService {
|
||||
});
|
||||
}
|
||||
|
||||
aesGenerateKey(bitLength: 128 | 192 | 256 | 512): Promise<CsprngArray> {
|
||||
return this.randomBytes(bitLength / 8);
|
||||
}
|
||||
|
||||
randomBytes(length: number): Promise<CsprngArray> {
|
||||
return new Promise<CsprngArray>((resolve, reject) => {
|
||||
crypto.randomBytes(length, (error, bytes) => {
|
||||
|
||||
Reference in New Issue
Block a user