Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Ovahlord/647f7beaef662b52c9d868907d9bb5a5 to your computer and use it in GitHub Desktop.
Save Ovahlord/647f7beaef662b52c9d868907d9bb5a5 to your computer and use it in GitHub Desktop.
Convert openssl .key file to .pem
For converting .key file to .pem file,
Your keys may already be in PEM format, but just named with .crt or .key.
If they begin with -----BEGIN and you can read them in a text editor (they use base64, which is readable in ASCII, not binary format), they are in PEM format.
If the file is in binary, for the server.crt, you would use
openssl x509 -inform DER -outform PEM -in server.crt -out server.crt.pem
For server.key, use openssl rsa in place of openssl x509.
The server.key is likely your private key, and the .crt file is the returned, signed, x509 certificate.
If this is for a Web server, and you cannot specify loading a separate private and public key, you may need to concatenate the two files. For this use: cat server.crt server.key > server.includesprivatekey.pem. I would recommend naming files with "includesprivatekey" to help you manage the permissions you keep with this file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment