• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7const assert = require('assert');
8const {
9  generateKeyPair,
10} = require('crypto');
11const {
12  assertApproximateSize,
13  testEncryptDecrypt,
14  testSignVerify,
15} = require('../common/crypto');
16
17// Test async RSA key generation with an encrypted private key, but encoded as DER.
18{
19  generateKeyPair('rsa', {
20    publicExponent: 0x10001,
21    modulusLength: 512,
22    publicKeyEncoding: {
23      type: 'pkcs1',
24      format: 'der'
25    },
26    privateKeyEncoding: {
27      type: 'pkcs8',
28      format: 'der'
29    }
30  }, common.mustSucceed((publicKeyDER, privateKeyDER) => {
31    assert(Buffer.isBuffer(publicKeyDER));
32    assertApproximateSize(publicKeyDER, 74);
33
34    assert(Buffer.isBuffer(privateKeyDER));
35
36    const publicKey = {
37      key: publicKeyDER,
38      type: 'pkcs1',
39      format: 'der',
40    };
41    const privateKey = {
42      key: privateKeyDER,
43      format: 'der',
44      type: 'pkcs8',
45      passphrase: 'secret'
46    };
47    testEncryptDecrypt(publicKey, privateKey);
48    testSignVerify(publicKey, privateKey);
49  }));
50}
51