Verify a RSA signature using only RSA encryption I'm trying to verify a RSA signed message, however, the API that I have access to in that environment only has encrypt and decrypt.
I think I understand that verification and encryption with public key are similar. Actually, running the following seems to work:

openssl rsautl -sign -in clear -inkey private_key.pem -out signed
openssl rsautl -encrypt -pubin -inkey public_key.pem -in signed -raw -hexdump


This second command will get the initial clear, padded (then I just need to unpad and verify that it matches the clear). However, the -raw is where I encounter an issue.
As the signed message is the size of the key, I can't encrypt it (the API will refuse, as does openssl if you omit -raw).

I'm not sure on how to proceed. I feel that what I'm trying to do should be possible.
The API you are trying to use automatically pads (probably RSAES-PKCS1-v1_5 padding). Instead you require it to verify and remove the padding during signature verification.

If you cannot skip the padding then you cannot use the API. Try and find a library that actually can verify instead. You shouldn't program RSA itself, but in the end it's just an algorithm. As long as you have access to the key - and preferably a big integer math library - you should be able to perform RSA modular exponentiation and verification / removal of the padding yourself.

You cannot just magic away 11 bytes that are added to the plaintext before modular exponentiation. OAEP would pad even more.



You could try and decrypt the signature with the public key and hope that the API detects the public key and performs the verification and unpadding instead itself, but that's a long shot. Note that you should get an error message if the padding cannot be verified.

Note that Diffie-Hellman also performs modular exponentiation. Sometimes you can use DH functionality to "raw decrypt" an RSA signature.