title: How to verify in pycrypto signature created by openssl?
body: <p>I've created private/public key in openssl, and signed some data:</p>
  
  <pre><code>openssl genrsa -out private.pem 1024
  openssl rsa -in private.pem -out public.pem -outform PEM -pubout
  echo 'data to sign' &gt; data.txt
  openssl dgst -md5 &lt; data.txt &gt; hash
  openssl rsautl -sign -inkey private.pem -keyform PEM -in hash  &gt; signature
  </code></pre>
  
  <p>now in python, I'm trying to verify this data:</p>
  
  
  
  <pre class="lang-python prettyprint-override"><code>pubKey = open('public.pem').read()
  data = open('data.txt').read()
  signature = open('signature').read()
  
  from Crypto import PublicKey
  key = PublicKey.RSA.importKey(pubKey)
  pub = key.publickey()
  hash = MD5.new(data).hexdigest()
  # here, hash is same, as contents of 'hash' file
  print pub.verify(hash, signature) # &lt;-- here
  </code></pre>
  
  <p>the problem is, that <code>pub.verify</code> expects second parameter to be one-element list with some large number. And I don't know how to convert binary data in file <code>signature</code> to this integer. Every example about pycrypto shows signature generated <em>from</em> pycrypto, and <code>key.sign()</code> generates correct signature in form <code>(1832273432...2340234L, )</code>. But I dont know how to use external signature.</p>
  
  <p>If this is necessary, below are additional informations, which I don't exactly know how to interpret:</p>
  
  <p>Brief technical information:</p>
  
  <ul>
  <li>Format of digital signature: PKCS#7 “Signed-Data”</li>
  <li>Public key procedure: DSS</li>
  <li>Key length: 512 – 1024 bits</li>
  <li>Public exponent:  2 +1</li>
  <li>Public key format: X.509 v3 certificate</li>
  <li>MD (Message Digest) algorithm: MD5 or RIPEMD-160 16</li>
  </ul>