This usually means that the encryption side and the decryption side use a different padding scheme. They must be the same on both sides.
If you use Bouncy Castle in Java, you can specify the padding scheme (in this case, the PKCS # 1 add-on) in the cipher as follows:
Cipher cipher = Cipher.getInstance("RSA/None/PKCS1Padding", "BC");
In openssl, you can specify the padding scheme in the encrypt / decrypt command:
openssl rsautl -pkcs -decrypt ...
The "-pkcs" parameter here indicates PKCS # 1 padding scheme.
Hope this helps.
source share