convert cer to csr using openssl or keytool

Is it possible to generate a csr file from cer file using openssl or keytool? I can see commands to convert the other way. Or, is it possible to generate a public pem file from the cer file?


You can create a CSR from a certificate using OpenSSL as follows:

openssl x509 -x509toreq -signkey ./server.key -in ./server.pem -out server.csr

will create a certificate request from the certificate and private key. Note that you must have the private key available for this to work as the csr is signed by the private key in order to provide proof of possession.

You can generate a .pem from a .cer in one of two ways:

  1. If the file is in DER format (a binary format) you can use: openssl x509 -inform DER in server.cer -out server.pem.

  2. If the file is in PEM format (a base64 text format) you can simply rename it from .cer to .pem. Remember the cer is only a file extension and doesn't really define the content of the file.