I have seen other posts about converting PEM file to crt and key files like this one but it didn't work for me.
Using openssl x509 -outform der -in your-cert.pem -out your-cert.crt
can generate a crt file but how to generate a corresponding key file? Assuming the key file has to be paired with the crt file?
There are posts like this one which suggests simply changing the file extension from .pem
to .crt
and .key
will do the job. I tried changing the file extension but when using the crt and key files to start a https server in golang; it didn't work. The error is: found a certificate rather than a key in the PEM for the private key
. This makes sense as I opened the PEM file which only contains ---BEGIN CERTIFICATE---
and END CERTIFICATE
. Nothing about the key.
Also tried openssl pkey -in mypemFile.pem -out foo.key
and openssl rsa -in mypemFile.pem -out foo.key
; both got error: Expecting: ANY PRIVATE KEY
My situation is I need to create a https server using Golang, which would require a crt and key file to start a HTTPS server e.g. err := s.ListenAndServeTLS("../../mycert.crt", "../../mykey.key")
, but I was given a PEM file from the company security team hence I want to convert the PEM file into crt and key files.