I follow OpenSSL to generate signatures. I use ruby 2.1.0 and create these signatures:
document = "This is a simple string document to be signed"
key = OpenSSL::PKey::RSA.new([private_key])
digest = OpenSSL::Digest::SHA256.new
signature = key.sign digest, document
The signal is transmitted and gets to the destination where it should be checked. To check, I like the following:
key = OpenSSL::PKey::RSA.new([pubkey])
digest = OpenSSL::Digest::SHA256.new
key.verify digest, signature, document
This works because if we change only one letter of the document or signature, it returns an invalid result:
key.verify digest, signature, changed_document
But on the other SHA, the validation command still produces a valid result:
digest = OpenSSL::Digest::SHA256.new('this will generate different SHA')
key.verify digest, signature, document
It confused me. Should another SHA hash produce an invalid result? What is the role of the digest here?
source
share