I need to decrypt a message with the following logic
Logic RSA/ECB/PKCS1Decryption(Base64Decode(encryptedKey),B2C.cer)
Tried with two modules crypto & node-RSA returns a similar error.
RSA_padding_check_PKCS1_type_2:pkcs decoding error
Code
const privateKeyForDecryption = fs.readFileSync(path.resolve("./nsBank.key"));
// node-rsa module
function RSA_Decrypt(str){
var key = new nodeRSA(privateKeyForDecryption);
key.setOptions({encryptionScheme:'pkcs1'});
const decrypted = key.decrypt(str, 'base64');
return decrypted;
}
Error enter image description here // crypto module
function RSA_Decrypt(str){
const buffer = Buffer.from(str,"base64");
const decrypted = crypto.privateDecrypt({key:privateKeyForDecryption,padding:crypto.constants.RSA_PKCS1_PADDING}, buffer);
return decrypted;
}