I have a digital signature that was created using the following algorithm: a SHA-256 hash of the body of the message is calculated. It is then signed using an RSA private key and the result is base64-encoded.
Now, I have the RSA public key corresponding to that private key which was used to encrypt the hash. I want to decrypt the digital signature using the RSA public key so that it gives me the SHA-256 hash of the body of message that was sent by the server. I can later compare this with the SHA-256 hash of the body of the message that was received.
I am unable to recover the SHA-256 hash (I'm expecting to get 64 hex characters). Here is what I am doing:
I save the public key in the following format in a file,
-----BEGIN PUBLIC KEY----- the key itself -----END PUBLIC KEY------
With the following command:
openssl rsa -noout -text -pubin < pub.key
It tells me that the key is of length 2048 bits.
I save the base64-encoded digital signature in a file called
sig.txt and then use the
-verify option of
openssl to retrieve the data.
openssl rsautil -verify -in sig.txt -inkey pub.key -pubin
This gives me the error:
RSA_EAY_PUBLIC_DECRYPT: data greater than mod len: rsa_eay.c
Please note that the signature in the file
sig.txt is in base64 encoded form.
How can I use the RSA public key to decrypt this signature to recover the SHA-256 hash?