title: How can I use OpenSSL to encrypt a message using my public key and then decrypt it using my private key?
body: <p>Here is what I've tried:</p>
  
  <p><strong>Encrypt message w/ my public key</strong></p>
  
  <pre><code>openssl enc -aes-256-cbc -salt -kfile key.pub -in message.txt -out message.enc
  </code></pre>
  
  <p><strong>Decrypt message using my private key</strong></p>
  
  <pre><code>openssl enc -d -aes-256-cbc -salt -in message.enc -pass file:mykey.pem 
  </code></pre>
  
  <p><strong>Error from decryption</strong></p>
  
  <pre><code>bad decrypt
  452:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:330:
  </code></pre>