gossl icon indicating copy to clipboard operation
gossl copied to clipboard

Convert certificates/keys between different formats

Open aslafy-z opened this issue 3 years ago • 3 comments

Thank you for your work on this project! I'd love to see the following new feature in the CLI:

Ability to convert certificates/keys between PEM to PKCS12 (with password support), and the other way around.

aslafy-z avatar Apr 11 '22 13:04 aslafy-z

Hello @aslafy-z Thanks for mentioning about the issue. I can work on it but I need to understand it well. Can you give an example with openssl command about this conversion?

yakuter avatar Apr 11 '22 13:04 yakuter

@yakuter we also need to convert pfx to cert.pem and cert.key.

Here is the openssl doc to do that:

Conversion to a combined PEM file

To convert a PFX file to a PEM file that contains both the certificate and private key, the following command needs to be used: openssl pkcs12 -in filename.pfx -out cert.pem -nodes

Conversion to separate PEM files

We can extract the private key form a PFX to a PEM file with this command: openssl pkcs12 -in filename.pfx -nocerts -out key.pem

Exporting the certificate only: openssl pkcs12 -in filename.pfx -clcerts -nokeys -out cert.pem

Removing the password from the extracted private key: openssl rsa -in key.pem -out server.key

yusufozturk avatar Jun 21 '22 11:06 yusufozturk

Examples: https://github.com/junhwong/go-opensdk/blob/81e7b939e860502e6e29d4055ace4015025aab50/opensdk/utils.go https://github.com/yhinan/gui/blob/79031b74ee9a9f4d009282c331d0fe8d14fd8313/crypto/pfx/pfx.go

yusufozturk avatar Jun 21 '22 11:06 yusufozturk