Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

Is it possible to convert an SSL certificate from a .key file to a .pfx?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...