title: Python RSA Decryption Using OpenSSL Generated Keys
body: <p>Does anyone know the simplest way to import an OpenSSL RSA private/public key (using a  passphrase) with a Python library and use it to decrypt a message.</p>
  
  <p>I've taken a look at ezPyCrypto, but can't seem to get it to recognise an OpenSSL RSA key, I've tried importing a key with importKey as follows:</p>
  
  <pre><code>key.importKey(myKey, passphrase='PASSPHRASE')
  </code></pre>
  
  <p>myKey in my case is an OpenSSL RSA public/private keypair represented as a string.  </p>
  
  <p>This balks with:</p>
  
  <blockquote>
    <p>unbound method importKey() must be called with key instance as first
    argument (got str instance instead)</p>
  </blockquote>
  
  <p>The API doc says:</p>
  
  <blockquote>
    <p>importKey(self, keystring, **kwds)</p>
  </blockquote>
  
  <p>Can somebody suggest how I read a key in using ezPyCrypto?  I've also tried:</p>
  
  <pre><code>key(key, passphrase='PASSPHRASE')
  </code></pre>
  
  <p>but this balks with:</p>
  
  <blockquote>
    <p>ezPyCrypto.CryptoKeyError: Attempted
    to import invalid key, or passphrase
    is bad</p>
  </blockquote>
  
  <p>Link to docs here:</p>
  
  <p><a href="http://www.freenet.org.nz/ezPyCrypto/detail/index.html" rel="nofollow noreferrer">http://www.freenet.org.nz/ezPyCrypto/detail/index.html</a></p>
  
  <p><strong>EDIT:</strong> Just an update on this.  Successfully imported an RSA key, but had real problem decrypting because eqPyCrypto doesn't support the AES block cipher.  Just so that people know.  I successfully managed to do what I wanted using ncrypt (<a href="http://tachyon.in/ncrypt/" rel="nofollow noreferrer">http://tachyon.in/ncrypt/</a>).  I had some compilation issues with M2Crypto because of SWIG  and OpenSSL compilation problems, <em>despite</em> having versions installed that exceeded the minimum requirements.  It would seem that the Python encryption/decryption frameworks are a bit of a minefield at the moment.  Ho hum, thanks for your help.</p>