Get private key from PEM

时间:2017-05-16 09:39:26

标签: java ssl https openssl pkcs#12

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.

1 个答案:

答案 0 :(得分:0)

我假设命令行会提示输入密码,但需要提供参数
-passin file:passphrase.txt


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