Why does SignHash need to know what hash algorithm was used?

前端 未结 2 1366
北恋
北恋 2021-01-12 09:51

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

相关标签:
2条回答
  • 2021-01-12 10:16

    Thanks to Iridium for getting me thinking along the right lines here.

    The recipient gets two things:

    • The message
    • The signature (encrypted by sender's private key)

    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.

    0 讨论(0)
  • 2021-01-12 10:17

    For example, PKCS#1 padding for RSA signature implies adding a hash function identifier to the hash value before signing.

    As I see, you are using exactly this method. Try to set another algorithm with same digest length and you'll see that signatures are different.

    0 讨论(0)
提交回复
热议问题