Decrypt PEM containing key and certificate

1

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?

Madden

Posted 2018-03-21T13:32:24.033

Reputation: 111

Answers

3

To decrypt a private key from a pem file you would do something like this with a subcommand (rsa 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.

bbaassssiiee

Posted 2018-03-21T13:32:24.033

Reputation: 1 225

I think you need a subcommand in there. Maybe pkey? Please @ me when you fix it and I'll remove my downvote. – Spiff – 2018-03-21T19:51:13.267

Yes, it should be pkey for new format keys (PKCS8) or rsa for the older PKCS1. – user1686 – 2018-03-21T21:59:14.627

Added suggestion of @Spiff – bbaassssiiee – 2018-03-24T08:09:18.650

To do it without editing: openssl x509 <in >out; openssl pkey <in >>out – dave_thompson_085 – 2018-03-24T10:04:12.190