mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: https://github.com/nodejs/node/pull/64960 Fixes: https://github.com/nodejs/node/issues/48379 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh>
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const {
|
|
generateKeyPairSync,
|
|
} = require('crypto');
|
|
const {
|
|
assertApproximateSize,
|
|
hasFIPS,
|
|
testEncryptDecrypt,
|
|
testSignVerify,
|
|
pkcs1PubExp,
|
|
pkcs8Exp,
|
|
} = require('../common/crypto');
|
|
|
|
// To make the test faster, we will only test sync key generation once and
|
|
// with a relatively small key.
|
|
{
|
|
const isFips = hasFIPS(3);
|
|
const ret = generateKeyPairSync('rsa', {
|
|
publicExponent: isFips ? 0x10001 : 3,
|
|
modulusLength: isFips ? 2048 : 512,
|
|
publicKeyEncoding: {
|
|
type: 'pkcs1',
|
|
format: 'pem'
|
|
},
|
|
privateKeyEncoding: {
|
|
type: 'pkcs8',
|
|
format: 'pem'
|
|
}
|
|
});
|
|
|
|
assert.strictEqual(Object.keys(ret).length, 2);
|
|
const { publicKey, privateKey } = ret;
|
|
|
|
assert.strictEqual(typeof publicKey, 'string');
|
|
assert.match(publicKey, pkcs1PubExp);
|
|
assertApproximateSize(publicKey, isFips ? 426 : 162);
|
|
assert.strictEqual(typeof privateKey, 'string');
|
|
assert.match(privateKey, pkcs8Exp);
|
|
assertApproximateSize(privateKey, isFips ? 1704 : 512);
|
|
|
|
testEncryptDecrypt(publicKey, privateKey);
|
|
testSignVerify(publicKey, privateKey);
|
|
}
|