'I am using node to encrypt and decrypt a message but the encryption works fin when I try to decrypt it will show me error

I am using node to encrypt and decrypt a message but the encryption works fin when I try to decrypt it will show me error "Error during decryption (probably incorrect key). Original error: Error: error:0407008A:RSA routines:RSA_padding_check_PKCS1_type_1:invalid padding"


 const keyData = `-----BEGIN PUBLIC KEY-----\n${publicKey}\n-----END PUBLIC KEY-----`;
    const rsaKey = new NodeRSA(keyData, "public", { encryptionScheme: "pkcs1" });
     const encryptPublic = (rawData) => {
      const dataString = JSON.stringify(rawData);
      const data = Buffer.from(dataString);
      return rsaKey.encrypt(data, "base64", "utf8");
  };
  let encriptedData = encryptPublic(body);
    const decryptPublic = (dataToDecrypt) => {
      const decryptedData = rsaKey.decryptPublic(dataToDecrypt, "utf8");
      return decryptedData;
    };
    let decryptBody = decryptPublic(encriptedData);```


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source