6

I have a .pem file which contains both my certificate and encrypted private key, ie:

Bag Attributes
....
-----BEGIN CERTIFICATE-----
....
-----END CERTIFICATE-----
Bag Attributes
....
-----BEGIN ENCRYPTED PRIVATE KEY-----
....
-----END ENCRYPTED PRIVATE KEY-----

And I need to instead have a .pem file containing both the certificate and the decrypted private key. How can I achieve this on linux, preferrably utilising the openssl application?

1 Answer 1

14

To decrypt a private key from a pem file you would do something like this with a subcommand (rsa, pkey, pkcs8, pkcs12):

openssl rsa -in inputfilename -out outputfilename

Your input file is different because you concatenated both keys in one file. But you can simple edit the pem file to split it in 2 files.

5
  • I think you need a subcommand in there. Maybe pkey? Please @ me when you fix it and I'll remove my downvote.
    – Spiff
    Mar 21, 2018 at 19:51
  • Yes, it should be pkey for new format keys (PKCS8) or rsa for the older PKCS1. Mar 21, 2018 at 21:59
  • Added suggestion of @Spiff Mar 24, 2018 at 8:09
  • 2
    To do it without editing: openssl x509 <in >out; openssl pkey <in >>out Mar 24, 2018 at 10:04
  • 1
    Hi All, is there any updated answer for this? I have the same issue. These commands did not work for me
    – CoderBro
    Oct 26, 2022 at 5:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .