diff --git a/lib/config/decrypt.js b/lib/config/decrypt.js index 93d8ffb25bda5bca1d281d75e9c1c61557e5b3bb..939d40d31f15a3e7299e54f67ca54eb878d1713e 100644 --- a/lib/config/decrypt.js +++ b/lib/config/decrypt.js @@ -15,9 +15,25 @@ function decryptConfig(config, privateKey) { if (privateKey) { for (const [eKey, eVal] of Object.entries(val)) { try { - const decryptedStr = crypto - .privateDecrypt(privateKey, Buffer.from(eVal, 'base64')) - .toString(); + let decryptedStr; + try { + logger.debug('Trying default padding'); + decryptedStr = crypto + .privateDecrypt(privateKey, Buffer.from(eVal, 'base64')) + .toString(); + } catch (err) { + logger.debug('Trying RSA_PKCS1_PADDING'); + decryptedStr = crypto + .privateDecrypt( + { + key: privateKey, + padding: crypto.constants.RSA_PKCS1_PADDING, + }, + Buffer.from(eVal, 'base64') + ) + .toString(); + // let it throw if the above fails + } logger.info(`Decrypted ${eKey}`); if (eKey === 'npmToken') { const token = decryptedStr.replace(/\n$/, '');