main content Main Menu Footer
Service Catalog

Useful OpenSSL Commands

OpenSSL is a very useful and practical tool for working with digital certificates, with the advantage of being an open, robust, and actively developed project. More details at OpenSSL.org.

Below, we list the most used OpenSSL commands for operations with digital certificates:

Generate RSA key:

2048-bit keys:

$ openssl genrsa -out key_name.key 2048

Before generating the key pair, check the key size and type supported by the Certification Authority that will sign the certificate.

Generate a certificate request:

$ openssl req -new -key key_name.key -out request.csr

The request fields must be filled in as follows:

  • Country Name (2 letter code) [AU]: BR
  • State or Province Name (full name): Sao Paulo
  • Locality Name (e.g., city) [ ]: Campinas
  • Organization Name (eg, company) [Internet Widgits Pty Ltd]: Unicamp
  • Organizational Unit Name (eg, section) [ ]: Unit Acronym
  • Common Name (eg server FQDN or YOUR name) [ ]: FQDN of the service or machine
  • Email Address [ ]: Email of the person responsible for the service

Note: FQDN: Full name (including domain) of the service registered in the DNS.

The .csr file resulting from this command is what must be sent to the Certificate Authority to be signed.

Display request in text format:

$ openssl req -inform PEM -in requisicao.csr -text

This command allows you to view the content of the certificate request in text format, very useful for checking the data entered, for example.

Convert DER Signed Certificate to PEM

$ openssl x509 -in certificate.cer -inform der -out certificate.pem -outform pem

Convert PEM Signed Certificate to DER

$ openssl x509 -in certificate.pem -inform pem -out certificate.cer -outform der

DER is a binary format, usually presented by a file with the extension .cer. The PEM format consists of encoded text, usually presented with the extension .pem or .crt. 
See the documentation for the service you are configuring for more information about supported certificate formats.

Display the certificate in text format

$ openssl x509 -inform PEM -in certificate.pem -text

In this case, the certificate is in PEM (text-encoded) format. For a certificate in DER (binary) format, replace the parameter – inform PEM with – inform DER.

Go to top