blueSky
blueSky

Reputation: 53

Get private key from PEM

PEM file content.I have the passphrase of PEM file as well.

*Bag Attributes
    localKeyID: 12 7B 3C 4C ... 
subject=/C..OTHER FIELDS
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
Bag Attributes
    localKeyID: 12 7B 3C 4C ..
Key Attributes: <No Attributes>
-----BEGIN ENCRYPTED PRIVATE KEY-----
...
-----END ENCRYPTED PRIVATE KEY-----*

I am able to extract certificate from PEM file with command.

openssl x509 -outform der -in client.pem -out your-cert.crt

But I am not able to extract private key.Tried below listed commands. OpenSSL hangs for both the commands. Am I missing something obvious here ?

openssl pkey -in client.pem -out key.pem

I need to extract client cert and key file to create SSLSocketFactory object in java.

Upvotes: 2

Views: 31972

Answers (1)

blueSky
blueSky

Reputation: 53

I assumed commandline will prompt for entering the passphrase but it needs to be provided argument
-passin file:passphrase.txt


openssl pkey -inform PEM -outform DER -in client.pem -passin file:passphrase.txt -out key.pem

Upvotes: 3

Related Questions