Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/parallel/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions test/parallel/test-crypto-private-decrypt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const common = require('../common');
const crypto = require('crypto');

if (!common.hasCrypto) {
common.skip('missing crypto');
}

const keys = crypto.generateKeyPairSync('rsa', {
modulusLength: 2048,
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
});

const empty = '';

const ciphertext = crypto.publicEncrypt({
oaepHash: 'sha1',
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
key: keys.publicKey
}, Buffer.from(empty)).toString('base64');

const plaintext = crypto.privateDecrypt({
oaepHash: 'sha1',
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
key: keys.privateKey
}, Buffer.from(ciphertext, 'base64')).toString('utf8').trim();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the last trim() function maynot a good idea. In my opinion, the fix should be in the internal C level.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed encryption and decryption logic for improved accuracy and consistency.


console.log('Decrypt', plaintext);
console.assert(empty === plaintext, 'rsa-oaep `encrypt` empty string is success, but `decrypt` got unexpected string.');