Decrypt PEM containing key and certificate (2024)

4

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?

Add a comment |

1 Answer

11

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.

answered Mar 21, 2018 at 17:53

Decrypt PEM containing key and certificate (2)

bbaassssiieebbaassssiiee

1,36511 gold badge1111 silver badges1717 bronze badges

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

  • Hi All, is there any updated answer for this? I have the same issue. These commands did not work for me

    iUser

    Oct 26, 2022 at 5:04

Add a comment |

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

or ask your own question.

Decrypt PEM containing key and certificate (2024)
Top Articles
Latest Posts
Article information

Author: Ray Christiansen

Last Updated:

Views: 6774

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Ray Christiansen

Birthday: 1998-05-04

Address: Apt. 814 34339 Sauer Islands, Hirtheville, GA 02446-8771

Phone: +337636892828

Job: Lead Hospitality Designer

Hobby: Urban exploration, Tai chi, Lockpicking, Fashion, Gunsmithing, Pottery, Geocaching

Introduction: My name is Ray Christiansen, I am a fair, good, cute, gentle, vast, glamorous, excited person who loves writing and wants to share my knowledge and understanding with you.