mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 23:33:31 +00:00
generate keypair on registration
This commit is contained in:
@@ -170,6 +170,15 @@ describe('NodeCrypto Function Service', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('rsaGenerateKeyPair', () => {
|
||||
testRsaGenerateKeyPair(1024);
|
||||
testRsaGenerateKeyPair(2048);
|
||||
|
||||
// Generating 4096 bit keys is really slow with Forge lib.
|
||||
// Maybe move to something else if we ever want to generate keys of this size.
|
||||
// testRsaGenerateKeyPair(4096);
|
||||
});
|
||||
|
||||
describe('randomBytes', () => {
|
||||
it('should make a value of the correct length', async () => {
|
||||
const nodeCryptoFunctionService = new NodeCryptoFunctionService();
|
||||
@@ -302,6 +311,16 @@ function testCompare(fast = false) {
|
||||
});
|
||||
}
|
||||
|
||||
function testRsaGenerateKeyPair(length: 1024 | 2048 | 4096) {
|
||||
it('should successfully generate a ' + length + ' bit key pair', async () => {
|
||||
const cryptoFunctionService = new NodeCryptoFunctionService();
|
||||
const keyPair = await cryptoFunctionService.rsaGenerateKeyPair(length);
|
||||
expect(keyPair[0] == null || keyPair[1] == null).toBe(false);
|
||||
const publicKey = await cryptoFunctionService.rsaExtractPublicKey(keyPair[1]);
|
||||
expect(Utils.fromBufferToB64(keyPair[0])).toBe(Utils.fromBufferToB64(publicKey));
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
function makeStaticByteArray(length: number) {
|
||||
const arr = new Uint8Array(length);
|
||||
for (let i = 0; i < length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user