{"id":79,"date":"2009-09-03T10:56:12","date_gmt":"2009-09-03T09:56:12","guid":{"rendered":"http:\/\/fapg.nsk.pt\/?p=79"},"modified":"2012-01-13T13:06:27","modified_gmt":"2012-01-13T12:06:27","slug":"openssl-utils-commands","status":"publish","type":"post","link":"https:\/\/fapg.nsk.pt\/en\/2009\/09\/openssl-utils-commands\/","title":{"rendered":"openssl utils commands"},"content":{"rendered":"<p>This post describes the most used commands\u00a0 from OpenSSL tool.<\/p>\n<h2><!--more-->General OpenSSL Commands<\/h2>\n<p>These commands allow you to generate CSRs, Certificates, Private Keys and do other miscellaneous tasks.<\/p>\n<ul>\n<li><strong>Generate a new private key and Certificate Signing Request:<\/strong><\/li>\n<ul>\n<li>openssl req -out CSR.csr -pubkey -new -keyout privateKey.key<\/li>\n<\/ul>\n<ul>\n<li>openssl req -nodes -newkey rsa:2048 -keyout privateKey.key -out CSR.csr (this generates a 2048 bits certificate request)<\/li>\n<\/ul>\n<li><strong>Generate a certificate signing request (CSR) for an existing private key: <\/strong>openssl req -out CSR.csr -key privateKey.key -new<\/li>\n<li><strong>Generate a certificate signing request based on an existing certificate<\/strong>: openssl x509 -x509toreq -in certificate.crt -out CSR.csr -signkey privateKey.key<\/li>\n<li><strong>Generate a self-signed certificate: <\/strong>openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout privateKey.key -out certificate.crt<\/li>\n<li><strong>Remove a passphrase from a private key<\/strong>: openssl rsa -in privateKey.pem -out newPrivateKey.pem<\/li>\n<\/ul>\n<h2>Checking Using OpenSSL<\/h2>\n<p>If you need to check the information within a Certificate, CSR or Private Key, use these commands.<\/p>\n<ul>\n<li><strong>Check a Certificate Signing Request (CSR): <\/strong>openssl req -text -noout -verify -in CSR.csr<\/li>\n<li><strong>Check a private key<\/strong>: openssl rsa -in privateKey.key -check<\/li>\n<li><strong>Check a certificate: <\/strong>openssl x509 -in certificate.crt -text -noout<\/li>\n<li><strong>Check a PKCS#12 file (.pfx or .p12)<\/strong>: openssl pkcs12 -info -in keyStore.p12<\/li>\n<\/ul>\n<h2>Converting Using OpenSSL<\/h2>\n<p>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.<\/p>\n<ul>\n<li><strong>Convert a DER file (.crt .cer .der) to PEM<\/strong>: openssl x509 -inform der -in certificate.cer -out certificate.pem<\/li>\n<li><strong>Convert a PEM file to DER: <\/strong>openssl x509 -outform der -in certificate.pem -out certificate.der<\/li>\n<li><strong>Convert a PKCS#12 file (<\/strong><strong>.pfx .p12<\/strong><strong>) containing a private key and certificates to PEM<\/strong>: openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodesYou can add -nocerts to only output the private key or add -nokeys to only output the certificates.<\/li>\n<li><strong>Convert a PEM certificate file and a private key to PKCS#12 (.pfx .p12)<\/strong>: openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt<\/li>\n<\/ul>\n<h2>Check whether a private key \/ CSR matches a certificate<\/h2>\n<p>These commands allow you to compare the modulus of the private key, the modulus of a certificate and the modulus of a CSR. If the results are the same, you have a match:<\/p>\n<ul>\n<li><strong>Modulus of a Certificate:<\/strong> openssl x509 -noout -modulus -in certificate.crt | openssl md5<\/li>\n<li><strong>Modulus of a private key (may require password):\u00a0<\/strong>openssl rsa -noout -modulus -in privateKey.key | openssl md5<\/li>\n<li><strong>Modulus of a CSR:\u00a0<\/strong>openssl req -noout -modulus -in CSR.csr | openssl md5<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>The site that describes OpenSSL tool and much more, can be found <a href=\"http:\/\/www.sslshopper.com\" target=\"_blank\">here<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>This post describes the most used commands\u00a0 from OpenSSL tool.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[16,5],"tags":[],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-command-line","category-linux"],"_links":{"self":[{"href":"https:\/\/fapg.nsk.pt\/en\/wp-json\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fapg.nsk.pt\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fapg.nsk.pt\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fapg.nsk.pt\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fapg.nsk.pt\/en\/wp-json\/wp\/v2\/comments?post=79"}],"version-history":[{"count":11,"href":"https:\/\/fapg.nsk.pt\/en\/wp-json\/wp\/v2\/posts\/79\/revisions"}],"predecessor-version":[{"id":81,"href":"https:\/\/fapg.nsk.pt\/en\/wp-json\/wp\/v2\/posts\/79\/revisions\/81"}],"wp:attachment":[{"href":"https:\/\/fapg.nsk.pt\/en\/wp-json\/wp\/v2\/media?parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fapg.nsk.pt\/en\/wp-json\/wp\/v2\/categories?post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fapg.nsk.pt\/en\/wp-json\/wp\/v2\/tags?post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}