title: Encrypting private key in Python
body: <p>I have a private key in DER format. I am trying to convert it to PEM and simultaneously encrypt the private key with a passphrase.</p>
  
  <p>Here is the openssl command that I am using to convert and encrypt:</p>
  
  <pre class="lang-sh prettyprint-override"><code>&gt; openssl rsa -aes256 -inform der -in temp_key.der -outform pem -passout pass:&lt;password&gt;
  </code></pre>
  
  <p>I am trying to implement a similar logic in Python where I have the data for the key in-memory in DER format.
  I want to change it to PEM, encrypt it and then store to a file.</p>
  
  <p>I am not very well versed with Python's Crypto libraries and I am having a hard time to figure out the right way to convert and encrypt my key data.</p>