Skip to content

Commit 96487d5

Browse files
committed
modify test
1 parent b306018 commit 96487d5

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (!common.hasCrypto)
4+
common.skip('missing crypto');
5+
6+
// Test for https://github.com/nodejs/node/issues/40814
7+
8+
const assert = require('assert');
9+
const crypto = require('crypto');
10+
11+
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
12+
modulusLength: 2048,
13+
publicKeyEncoding: {
14+
type: 'spki',
15+
format: 'pem'
16+
},
17+
privateKeyEncoding: {
18+
type: 'pkcs8',
19+
format: 'pem',
20+
cipher: 'aes-128-ecb',
21+
passphrase: 'abcdef'
22+
}
23+
});
24+
assert.notStrictEqual(privateKey.toString(), '');
25+
26+
const msg = 'The quick brown fox jumps over the lazy dog';
27+
28+
const encryptedString = crypto.privateEncrypt({
29+
key: privateKey,
30+
passphrase: 'abcdef'
31+
}, Buffer.from(msg)).toString('base64');
32+
const decryptedString = crypto.publicDecrypt(publicKey, Buffer.from(encryptedString, 'base64')).toString();
33+
console.log(`Encrypted: ${encryptedString}`);
34+
console.log(`Decrypted: ${decryptedString}`);
35+
36+
assert.notStrictEqual(encryptedString, '');
37+
assert.strictEqual(decryptedString, msg);

0 commit comments

Comments
 (0)