title: M2crypto signature "algorithm"
body: <p>These two codes provide the same signature, which is expected:</p>
  
  <p>code1:</p>
  
  <pre><code>from M2Crypto import RSA, EVP
  import base64, hashlib
  
  text = "some text"
  
  pkey = EVP.load_key("mykey.pem")  #"mykey.pem" was generated as: openssl genrsa -des3 -out mykey.pem 2048
  pkey.sign_init()
  pkey.sign_update(text)
  signature = pkey.sign_final()
  print base64.b64encode(signature)
  </code></pre>
  
  <p>code2:</p>
  
  <pre><code>pkey = RSA.load_key("mykey.pem")
  signature = pkey.sign(hashlib.sha1(text).digest())
  print base64.b64encode(signature)
  </code></pre>
  
  <p>However, if I want to "imitate" the signature algorithm, i.e. encrypting the digest with the private key, I get a different signature, i.e.:</p>
  
  <pre><code>pkey = RSA.load_key("mykey.pem")
  signature = pkey.private_encrypt(hashlib.sha1(text).digest(), RSA.pkcs1_padding)
  print base64.b64encode(signature)  #different from the two above
  </code></pre>
  
  <p>Could you please provide some explanation? What is wrong with the latter way of signing?</p>