Version
23.7.0
Platform
Subsystem
crypto
What steps will reproduce the bug?
the crypto.privateDecrypt method sames changed the behavior since node23.7. I'm not sure that is a bug or feature. Reproduce codes as below:
// file: test-crypto-private-decrypt.jsconstcrypto=require('crypto');constkeys=crypto.generateKeyPairSync('rsa',{modulusLength: 2048,publicKeyEncoding: {type: 'spki',format: 'pem'},privateKeyEncoding: {type: 'pkcs8',format: 'pem'},});constempty='';constciphertext=crypto.publicEncrypt({oaepHash:'sha1',padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,key: keys.publicKey,},Buffer.from(empty)).toString('base64');constplaintext=crypto.privateDecrypt({oaepHash: 'sha1',padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,key: keys.privateKey},Buffer.from(ciphertext,'base64')).toString('utf8');console.assert(empty===plaintext,'rsa-oaep `encrypt` empty string is success, but `decrypt` got unexpected string.');when run the code, such as node test-crypto-private-decrypt.js in node23.7.0. The terminal prompted the message:
Assertion failed: rsa-oaep `encrypt` empty string is success, but `decrypt` got unexpected string.
How often does it reproduce? Is there a required condition?
no extra conditions.
What is the expected behavior? Why is that the expected behavior?
the privateDecrypt behavior should be same as before >= 10 < 23.7
What do you see instead?
Assertion failed: rsa-oaep encrypt empty string is success, but decrypt got unexpected string.
Additional information
The failed CI was here, message as below:
1) lib/rsa
Rsa::decrypt
method `decrypt` should returns an empty string when `ciphertext` is the input via `Rsa.encrypt` and `privateKeyCertificate` is a `pem` buffer:
AssertionError: expected '\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000' to be empty
at Assertion.fail (node_modules/should/cjs/should.js:275:17)
at Assertion.value [as empty] (node_modules/should/cjs/should.js:356:19)
at Context.<anonymous> (tests/lib/rsa.test.js:120:68)
at process.processImmediate (node:internal/timers:511:21)
2) lib/rsa
Rsa::decrypt
method `decrypt` should returns an empty string when `ciphertext` is the input via `Rsa.encrypt` and `privateKeyCertificate` is a pkcs8 `pem` String:
AssertionError: expected '\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000' to be empty
at Assertion.fail (node_modules/should/cjs/should.js:275:17)
at Assertion.value [as empty] (node_modules/should/cjs/should.js:356:19)
at Context.<anonymous> (tests/lib/rsa.test.js:135:68)
at process.processImmediate (node:internal/timers:511:21)
Version
23.7.0
Platform
Subsystem
crypto
What steps will reproduce the bug?
the
crypto.privateDecryptmethod sames changed the behavior since node23.7. I'm not sure that is a bug or feature. Reproduce codes as below:when run the code, such as
node test-crypto-private-decrypt.jsin node23.7.0. The terminal prompted the message:How often does it reproduce? Is there a required condition?
no extra conditions.
What is the expected behavior? Why is that the expected behavior?
the
privateDecryptbehavior should be same as before>= 10 < 23.7What do you see instead?
Assertion failed: rsa-oaep
encryptempty string is success, butdecryptgot unexpected string.Additional information
The failed
CIwas here, message as below: