How do you verify an RSA SHA1 signature in Python?

后端 未结 8 1472
面向向阳花
面向向阳花 2020-11-29 00:35

I\'ve got a string, a signature, and a public key, and I want to verify the signature on the string. The key looks like this:

-----BEGIN PUBLIC KEY-----
MIGf         


        
8条回答
  •  悲&欢浪女
    2020-11-29 01:14

    A public key contains both a modulus(very long number, can be 1024bit, 2058bit, 4096bit) and a public key exponent(much smaller number, usually equals one more than a two to some power). You need to find out how to split up that public key into the two components before you can do anything with it.

    I don't know much about pycrypto but to verify a signature, take the hash of the string. Now we must decrypt the signature. Read up on modular exponentiation; the formula to decrypt a signature is message^public exponent % modulus. The last step is to check if the hash you made and the decrypted signature you got are the same.

提交回复
热议问题