2

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;
}

Error enter image description here

  • There isn't nearly enough here to figure out the problem. Maybe you are using the wrong private key, maybe the data is corrupted, maybe your decryption does not match up with the encryption. – President James K. Polk Jun 10 '20 at 13:25
  • 1
    #1privateKey - This private key works with another context. So we can't suspect private key. #2corrupteddata - There is a chance to occur it is a string from a response object. we have to perform base64 decoding. Is there any mistake in base64 decoding. this is m first code. #3 Encryption Decryption Mismatch - Could you please help me to verify the code snippet with the LOGIC (RSA/ECB/PKCS1Decryption(Base64Decode(encryptedKey),B2C.cer)) in Decryption. – Santo Varghese Jun 11 '20 at 04:25

0 Answers0