This may be a question for http://crypto.stackexchange.com, but I thought I'd try it here first as the answer may relate to .NET rather than the encryption algorithm itself.
In the RSACryptoServiceProvider class, there's a method SignHash, which:
Computes the signature for the specified hash value by encrypting it with the private key.
The first argument is the hash value of the data (which seems fair), but the second is a string stating the algorithm used to create the hash value.
The question is why does the hash algorithm matter? Surely all the method needs to do is encrypt the given value using its private key and return the result? And if it really does need to know, why doesn't RSACryptoServiceProvider have a method which does just that (Along with an appropriate Verify method)?
Thanks to Iridium for getting me thinking along the right lines here.
The recipient gets two things:
To verify the message, the recipient is required to decrypt the signature using the sender's public key, and check that against the hash of the message.
If the hash algorithm isn't specified to the recipient, they have no way of knowing how to hash the message, so they can't verify it.
So the algorithm must be specified to the recipient.
In order for the hash algorithm to be specified by the sender (who knows how the signature was created), and not modifiable by anyone else, it needs to be included inside the signature, and encrypted alongside the hash.
So in order to create a useful signature, the hashing algorithm needs to be specified when encrypting the hash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With