title: How can I decrypt ciphertext from openssl aes-256 using an RSA keyfile
body: <p>I'm devising an encryption scheme to send files to an embedded device. Developers can log in via a shared public key, so it makes sense to use this same key to encrypt/decrypt files sent to it. Files are only packaged by the developers, so this public key is never given out.</p>
  
  <p>The files sent only need to be secure enough to make it difficult to decrypt, not anything NSA quality or anything.</p>
  
  <p>I can encrypt/decrypt using something like this:</p>
  
  <pre><code>cat file | openssl [-d] aes-256-cbc -kfile path/to/public/key &gt; outfile.aes
  </code></pre>
  
  <p>This is working great, except that I'd like to do this in the server code. I can shell out, but I'd rather do it in code.</p>
  
  <p>I grabbed the base64 data from the key, but when I decode it, I get a 279 byte array, but I need a 256-bit key (32 bytes).</p>
  
  <p>What exactly does openssl do with the keyfile and how can I emulate it in code?</p>
  
  <p>I tried <code>man openssl</code>, but I didn't find anything useful.</p>
  
  <p>If it matters, I'm doing this in Go.</p>