{"id":1322,"date":"2012-09-05T15:45:51","date_gmt":"2012-09-05T07:45:51","guid":{"rendered":"http:\/\/rmohan.com\/?p=1322"},"modified":"2012-09-05T15:45:51","modified_gmt":"2012-09-05T07:45:51","slug":"openssl-usage","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=1322","title":{"rendered":"OpenSSL Usage"},"content":{"rendered":"<p>List available Ciphers:<br \/> openssl ciphers -v<br \/> openssl ciphers -v tls1 #only TLS ciphers<br \/> openssl list-cypher-commands<br \/> openssl ciphers -v &#8216;HIGH&#8217; #only good ciphers<\/p>\n<p> Test OpenSSL Speed:<br \/> openssl speed<br \/> openssl speed rsa #test only rsa<\/p>\n<p> Generate self-signed cert:<br \/> openssl req \\<br \/> -x509 -nodes -days 365 \\<br \/> -newkey rsa:1024 -keyout mycert.pem -out mycert.pem<br \/> OR<br \/> openssl req \\<br \/> -x509 -nodes -days 365 \\<br \/> -subj &#8216;\/C=US\/ST=Oregon\/L=Portland\/CN=www.madboa.com&#8217; \\<br \/> -newkey rsa:1024 -keyout mycert.pem -out mycert.pem<\/p>\n<p> MD5 or SHA1 digest of file:<br \/> openssl dgst -md5 filename<br \/> openssl dgst -sha1 filename<\/p>\n<p> Base64 encode \/ decode a file:<br \/> openssl enc -base64 -in infile.txt #encode to stdout<br \/> openssl enc -base64 -in infile.txt -out outfile.txt #encode to a file<br \/> echo &#8220;encode me&#8221; | openssl enc -base64 #encode through a pipe<br \/> echo &#8220;Zw5jb2RlIGllCg==&#8221; | openssl enc -base64 -d #decode through a pipe<\/p>\n<p> Encrypt a file using 256-bit AES in CBC mode<br \/> openssl enc -aes-256-cbc -salt -in file.txt -out file.enc<br \/> openssl enc -aes-256-cbc -salt -in file.txt \\<br \/> -out file.enc -pass pass:password<br \/> openssl enc -aes-256-cbc -salt -in file.txt \\<br \/> -out file.enc -pass file:\/path\/to\/passwd.txt<br \/> openssl enc -aes-256-cbc -a -salt -in file.txt -out file.enc #base64 for email<\/p>\n<p> Decrypt binary \/ base64 AES CBC file<br \/> openssl enc -d -aes-256-cbc -in file.enc<br \/> openssl enc -d -aes-256-cbc -a -in file.enc\u00a0 # decode with base64<\/p>\n<p> <strong>Encrypt a file using Triple DES with base64 &#8220;ASCII Armor&#8221;<\/strong><br \/> openssl enc -e -a -salt -des3 -in file.txt -out file.des3<\/p>\n<p> <strong>Decrypt a file encoded with Triple DES and base64 encoded<\/strong><br \/> openssl enc -d -a -in file.des3 -out file.txt <\/p>\n<p> <strong>Encrypt a file using Blowfish and base64 encode<\/strong><br \/> openssl enc -e -a -salt -bf -in file.txt -out file.blowfish<\/p>\n<p> <strong>Decrypt a file encoded with Blowfish and base64 encoded<\/strong><br \/> openssl enc -d -a -bf -in file.blowfish -out file.txt<\/p>\n<p> Generate an RSA key:<br \/> openssl genrsa<br \/> openssl genrsa -out mykep.pem 1024<br \/> openssl genrsa -des3 -out mykey.pem 1024<\/p>\n<p> Generate a public RSA key:<br \/> openssl rsa -in mykey.pem -pubout<\/p>\n<p> Generate a DES key:<br \/> openssl dsaparam -noout -out dsakey.pem -genkey 1024<\/p>\n<p> Generate a shadow-style password hash:<br \/> openssl passwd -1 MySecret<br \/> openssl passwd -1 -salt sXiKzkus MySecret #specific salt<\/p>\n<p> Test for prime number:<br \/> openssl prime 11905475924560753<\/p>\n<p> Generate random number: <br \/> openssl rand -base64 128 #128 random base64 bits<br \/> openssl rand -out random_data.bin 1024 #1024 random binary bits<br \/> head -c 32 \/dev\/urandom | openssl enc -base64 #better entropy<br \/> <strong><br \/> <\/strong><br \/> <strong>Create an SSL certificate:<\/strong><br \/> openssl genrsa -des3 -out server.key 1024\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # create keys<br \/> openssl req -new -key server.key -out server.csr\u00a0\u00a0 # create cert request<\/p>\n<p> cp server.key server.key.org\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0 # remove passphrase<br \/> openssl rsa -in server.key.org -out server.key<br \/> openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt\u00a0 # create cert<\/p>\n<p> <strong>Decode an SSL Cert:<\/strong><br \/> <strong>openssl x509 -in certificate.crt -text -noout<\/strong><br \/> <a href=\"http:\/\/www.sslshopper.com\/certificate-decoder.html\">http:\/\/www.sslshopper.com\/certificate-decoder.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>List available Ciphers: openssl ciphers -v openssl ciphers -v tls1 #only TLS ciphers openssl list-cypher-commands openssl ciphers -v &#8216;HIGH&#8217; #only good ciphers<\/p>\n<p> Test OpenSSL Speed: openssl speed openssl speed rsa #test only rsa<\/p>\n<p> Generate self-signed cert: openssl req \\ -x509 -nodes -days 365 \\ -newkey rsa:1024 -keyout mycert.pem -out mycert.pem OR openssl req [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1322"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1322"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1322\/revisions"}],"predecessor-version":[{"id":1323,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1322\/revisions\/1323"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}