views:

1523

answers:

3

Hi,

is there a way to convert from a .key file to a .pfx file? thank you.

EDIT: I only have the .key file but my hosting provider says that I could convert it to .pfx with just that file.

+2  A: 

You could try this
https://www.sslshopper.com/ssl-converter.html

openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt
fig
Hi Dave, the thing is that I only have a .key file, no .crt file. Is it possible that the .key contains the certificate?
Dawkins
My hosting provider insists that this is the format they use and that in it is contained the certificate.
Dawkins
A: 

According to the OpenSSL Command-Line HOWTO it should work using

# export mycert.key as PKCS#12 file mycert.pfx
openssl pkcs12 -export -out mycert.pfx -in mycert.key -name "My Certificate"
ISW
+1  A: 

To check if your .key file has everything you need:

#check if file contains a valid certificate:
openssl x509 -text -in file.key

It should print out certificate details. If it prints an error including the text "unable to load certificate", then your file is not sufficient.

#check if file contains a valid key:
openssl rsa -text -in file.key
openssl dsa -text -in file.key

One of the above commands should print out valid key details. The other will give an error with the text "expecting an rsa key" or "expecting a dsa key".

If the error text says "bad decrypt", you have provided an invalid passphrase, or the file is damaged.

If the error text says "Expecting: ANY PRIVATE KEY", then your file is not sufficient.

If you got a key, and one certificate which matches the key (and optionally some other certificates), then you have enough to convert the file to a pfx. Then, as ISW said, it's just a matter of

#convert file containing key and certificate(s) to PKCS#12 pfx file.
openssl pkcs12 -export -out file.pfx -in file.key

and you're done.

Stobor