gossl
gossl copied to clipboard
Convert certificates/keys between different formats
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.
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 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
Examples: https://github.com/junhwong/go-opensdk/blob/81e7b939e860502e6e29d4055ace4015025aab50/opensdk/utils.go https://github.com/yhinan/gui/blob/79031b74ee9a9f4d009282c331d0fe8d14fd8313/crypto/pfx/pfx.go