title: Authenticated encryption and OpenSSL keys
body: <p>So the main question is "can I store an OpenSSL private key (specifically an RSA private key) using authenticated encryption?".</p>
  
  <p>OpenSSL supports a wide variety of encryption options for keys, however it seems like many of them are only supported as outputs, not inputs. For example, <code>openssl genrsa -aes256</code> works fine and creates a key that you can decrypt and use later (but is using CBC mode), but if you do <code>openssl genrsa -aes-256-gcm</code> the resulting key cannot be used by OpenSSL. The exact error message appears to vary by version, latest 1.1.0h gives:</p>
  
  <pre><code>root@cb772d20894d:/# openssl genrsa -aes-256-gcm | openssl rsa
  Generating RSA private key, 2048 bit long modulus
  .................................................+++
  ................................................+++
  e is 65537 (0x010001)
  Enter pass phrase:
  Verifying - Enter pass phrase:
  Enter pass phrase:
  unable to load Private Key
  139772421357760:error:0906A065:PEM routines:PEM_do_header:bad decrypt:../crypto/pem/pem_lib.c:445:
  </code></pre>
  
  <p>While older versions don't even get that far with:</p>
  
  <pre><code>140678952371864:error:0906B072:PEM routines:PEM_get_EVP_CIPHER_INFO:unsupported encryption:pem_lib.c:544:
  </code></pre>
  
  <p>The same error is shown with <code>aes-256-ocb</code> and <code>aes-256-ccm</code>. I think that's all of the available authenticated ciphers? Mayhaps I've missed an option somewhere in OpenSSL to allow this?</p>