Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extract a key from an SSL certificate?

I have an SSL certificate I purchased in a .pem, .crt, .der format. I was wondering how I get the key file from the certificate. Is there any way of doing this?

like image 318
nkcmr Avatar asked Jul 09 '13 23:07

nkcmr


People also ask

Can I extract a private key from a certificate?

You can extract the public key. This has limited usefulness. Perhaps you are going to use the same key with another tool like SSH or PGP that doesn't use certificates. You can't derive the private key from a certificate.

Can we extract public key from certificate?

When you create a certificate, you can specify whether it is exportable. If a key is exportable, it can be extracted and put in a file along with the associated certificate. The file is written in an industry standard format, PKCS#12, which allows it to be transported to other platforms.


1 Answers

You can extract the public key. This has limited usefulness. Perhaps you are going to use the same key with another tool like SSH or PGP that doesn't use certificates.

With OpenSSL:

openssl x509 -pubkey -noout < cert.pem > pubkey.pem

You can't derive the private key from a certificate. That would make the whole thing quite pointless, wouldn't it?

like image 98
erickson Avatar answered Sep 21 '22 23:09

erickson