Question

There are a lot of reference for converting a key to pem but not the other way around. I followed these steps to create a .pem key for AWS load balancer. The top of the cert looks like

-----BEGIN RSA PRIVATE KEY-----
....
-----END RSA PRIVATE KEY-----

Now i have to use that to configure apache virtual domains and I need a .key format which should look like so:

-----BEGIN PRIVATE KEY-----
....
-----END PRIVATE KEY-----

virtual host:

<VirtualHost *:443>
  ...
  SSLCertificateFile /etc/pki/tls/certs/public.crt
  SSLCertificateKeyFile /etc/pki/tls/certs/mykey.key #<<<<<
  SSLCertificateChainFile /etc/pki/tls/certs/intermediate.crt
</VirtualHost>

my question is how do i go about converting a pem to a key?
something like:
openssl rsa -in /etc/pki/tls/certs/mykey.pem -outform ???

note, i saw something like this openssl x509 -outform der -in certificate.pem -out certificate.der but .der and .key is the same?

Was it helpful?

Solution

From Openssl pkcs8 default format gives RSA PRIVATE KEY (migrated from Stack Overflow):

Perform pkcs8 with -topk8 to convert this key from traditional format to pkcs#8 format.

openssl pkcs8 -topk8 -inform pem -in file.key -outform pem -nocrypt -out file.pem

Above, traditional format is -----BEGIN RSA PRIVATE KEY-----, and PKCS8 format is -----BEGIN PRIVATE KEY-----.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top