Forked from lkdocs/Python PyCrypto: Verify Signature Example.py
          
        
    
          Last active
          January 22, 2018 17:54 
        
      - 
      
- 
        Save pbteja1998/8ae4ab4b8204869646b475f7fad80562 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def verify_sign(public_key, signature, hashed_data): | |
| ''' | |
| Verifies with a public key from whom the data came that it was indeed | |
| signed by their private key | |
| param: public_key | |
| param: signature String signature to be verified | |
| return: Boolean. True if the signature is valid; False otherwise. | |
| ''' | |
| from Crypto.PublicKey import RSA | |
| from Crypto.Signature import PKCS1_v1_5 | |
| from base64 import b64decode | |
| pub_key = public_key | |
| rsakey = RSA.importKey(pub_key) | |
| signer = PKCS1_v1_5.new(rsakey) | |
| if signer.verify(hashed_data, b64decode(signature)): | |
| return True | |
| return False | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment