I want to 'manually' compare a digest/hash of a message with the decrypted signature value on this digest.
For this, I want to decrypt the signature value (the signed digest) of the message with the public key that belongs to the private key the digest was signed with in the first place.
I have the following items:
- The digest value in base64 of the message (calculated with SHA256)
- The signature value on the digest in base64 that has been signed with the private key (using SHA256 with RSA Encryption)
- The public key in .pem format belonging to the private key
- I have the actual message (it is in XML containing multiple signatures on different sections of the document). I already verified the signatures using the XML security library. I'm interested in only decrypting the signature value with the public key.
I'm kind of stuck of how I can achieve this using openssl.
I'm trying variations on the commands described here and here, however I'm kind of lost.
I suppose I should convert the signature from base64 value to octet using:
base64 --d sigfile > sigfile_octet
?
Then I'm using the command:
openssl rsautl -inkey pubkey.pem -pubin -in sigfile_octet
Does this give me the decrypted signature value in octet? What are the next steps I need to perform to compare it with the base64 digest?
p.s. I already verified the signature using Aleksey's XML security library, so I know the digest should match the decrypted signature value.
Your help would be very much appreciated!!
Kind regards,
Diederik