title: how to verify digital signature with public key - python
body: <p>i'm trying to verfy signature of file and i was given a message.txt(data) and message.txt.sign(which i assume that is the signature) i also given the public key(publickey.pem) now i wrote a code in python using pycharm and inspired by this code:</p>
  
  <pre><code>def verify_sign(public_key_loc, signature, data):
      '''
      Verifies with a public key from whom the data came that it was indeed 
      signed by their private key
      param: public_key_loc Path to 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 Crypto.Hash import SHA256 
      from base64 import b64decode 
      pub_key = open(public_key_loc, "r").read() 
      rsakey = RSA.importKey(pub_key) 
      signer = PKCS1_v1_5.new(rsakey) 
      digest = SHA256.new() 
      # Assumes the data is base64 encoded to begin with
      digest.update(b64decode(data)) 
      if signer.verify(digest, b64decode(signature)):
          return True
      return False
  </code></pre>
  
  <p>it dosent work for me  , any help please?!</p>