Most Popular

Login:

Your Login Details

Forget Your Password?

Create an account

The Most Common OpenSSL Commands

One of the most versatile SSL tools is OpenSSL which is an open source implementation of the SSL protocol. There are versions of OpenSSL for nearly every platform, including Windows, Linux, and Mac OS X. OpenSSL is commonly used to create the CSR and private key for many different platforms, including Apache. However, it also has hundreds of different functions that allow you to view the details of a CSR or certificate, compare an MD5 hash of the certificate and private key (to make sure they match), verify that a certificate is installed properly on any website, and convert the certificate to a different format. A compiled version of OpenSSL for Windows can be found here.

Below, we have listed the most common OpenSSL commands and their usage:

General OpenSSL Commands

These commands allow you to generate CSRs, Certificates, Private Keys and do other miscellaneous tasks.

  • Generate a new private key and Certificate Signing Request

    openssl req -out CSR.csr -pubkey -new -keyout privateKey.key

  • Generate a certificate signing request (CSR) for an existing private key

    openssl req -out CSR.csr -key privateKey.key -new

  • Generate a certificate signing request based on an existing certificate

    openssl x509 -x509toreq -in MYCRT.crt -out CSR.csr -signkey privateKey.key

  • Generate a self-signed certificate

    openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout privateKey.key -out certificate.crt

  • Remove a passphrase from a private key

    openssl rsa -in privateKey.pem -out newPrivateKey.pem

Checking Using OpenSSL

If you need to check the information within a Certificate, CSR or Private Key, use these commands.

  • Check a Certificate Signing Request (CSR)

    openssl req -text -noout -verify -in CSR.csr

  • Check a private key

    openssl rsa -in privateKey.key -check

  • Check a certificate

    openssl x509 -in certificate.crt -text -noout

  • Check a PKCS#12 file (.pfx or .p12)

    openssl pkcs12 -info -in keyStore.p12

Debugging Using OpenSSL

If you are receiving an error that the private doesn't match the certificate or that a certificate that you installed to a site is not trusted, try one of these commands.

  • Check an MD5 hash of the public key to ensure that it matches with what is in a CSR or private key

    openssl x509 -noout -modulus -in certificate.crt | openssl md5
    openssl rsa -noout -modulus -in privateKey.key | openssl md5
    openssl req -noout -modulus -in CSR.csr | openssl md5

  • Check an SSL connection. All the certificates (including Intermediates) should be displayed

    openssl s_client -connect https://www.paypal.com:443

Converting Using OpenSSL

These commands allow you to convert certificates and keys to different formats to make them compatible with specific types of servers or software. For example, you can convert a normal PEM file that would work with Apache to a PFX (PKCS#12) file and use it with Tomcat or IIS.

  • Convert a DER file (.crt .cer .der) to PEM

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

  • Convert a PEM file to DER

    openssl x509 -outform der -in certificate.pem -out certificate.der

  • Convert a PKCS#12 file (.pfx .p12) containing a private key and certificates to PEM

    openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes

    You can add -nocerts to only output the private key or add -nokeys to only output the certificates.

  • Convert a PEM certificate file and a private key to PKCS#12 (.pfx .p12)

    openssl pkcs12 -export -out certificate.pfx -inkey privateKey.txt -in certificate.crt -certfile CACert.crt

 Digg  Slashdot  del.icio.us  Reddit  furl

Posted on January 11, 2008
Robert
Posts: 2
Comment
Re: need to convert .cer to .pkcs format
Reply #6 on : Sat July 26, 2008, 14:38:13
Ravi,

A .cer file is usually in pem format so you can use the following command to convert a .cer to a pkcs12 format file but you will also need to have the private key available:

openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodesopenssl pkcs12 -export -out certificate.pfx -inkey privateKey.txt -in certificate.crt -certfile CACert.crtpkcs
ravi
Posts: 3
Comment
need to convert .cer to pkcs format
Reply #5 on : Sat July 26, 2008, 06:43:50
how to convert .cer file format to a .pkcs file format using openssl on windows
swapna
Posts: 1
Comment
Get locale specific x509 attributes
Reply #4 on : Tue June 17, 2008, 23:04:11
how to get locale specific x509 attributes( country name, locality name, etc...)or user defined attributes whithout prompting for entry, when generating self signed key and certificate.
alert
Posts: 3
Comment
error
Reply #3 on : Thu June 05, 2008, 01:39:03
There's an error in this step:

Generate a self-signed certificate
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout certificate.crt -out privateKey.key

it should be:

Generate a self-signed certificate
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout certificate.key -out privateKey.crt

Admin update: Thanks for pointing this out. It has now been updated.
Robert
Posts: 2
Comment
CSR to DER
Reply #2 on : Tue March 25, 2008, 21:26:30
Tom,

A CSR is a file that is created on the server with a private key. You don't convert it to a CER (certificate file) but you can use it to create a certificate that will work with the private key that you generated. To do this you will need to get a certificate from a Certificate Authority listed on this site. You could also try creating a self-signed certificate depending on your needs.
tom
Posts: 3
Comment
cer
Reply #1 on : Tue March 25, 2008, 15:19:19
i'd like to convert csr to cer

Write a comment


If you have trouble reading the code, click on the code itself to generate a new random code.
Security Code:
 
Post Comment