{"id":664,"date":"2012-04-07T19:45:37","date_gmt":"2012-04-07T19:45:37","guid":{"rendered":"http:\/\/joelinoff.com\/blog\/?p=664"},"modified":"2018-08-22T01:14:44","modified_gmt":"2018-08-22T08:14:44","slug":"c-class-that-interfaces-to-openssl-ciphers","status":"publish","type":"post","link":"https:\/\/joelinoff.com\/blog\/?p=664","title":{"rendered":"C++ class that interfaces to OpenSSL ciphers"},"content":{"rendered":"<p>I have developed a class named <a title=\"doxygen generated documentation\" href=\"http:\/\/projects.joelinoff.com\/cipher\/cipher-1.2\/doxydocs\/html\/\">Cipher<\/a> that allows you to encrypt and decrypt files or strings using the OpenSSL AES-256-CBC cipher and SHA1 digest algorithms. It is interoperable with the <code>openssl<\/code> command line tool which makes it a good introduction to using OpenSSL for ciphers.<\/p>\n<p>The project has been moved to github: <a href=\"https:\/\/github.com\/jlinoff\/openssl-aes-cipher\">https:\/\/github.com\/jlinoff\/openssl-aes-cipher<\/a>. The latest version is 1.3. It has been updated to work with the opaque contexts that were introduced in openssl-1.1.<\/p>\n<p>I am re-releasing version 1.2 into the public domain on 2013-11-21 because I wish that I had found something like it when I was starting out with OpenSSL.<br \/>\n<!--more--><\/p>\n<div style=\"margin-left: 20px;\">\n<table>\n<thead>\n<tr>\n<th nowrap=\"nowrap\">Release<\/th>\n<th>Date<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"right\">1.2<\/td>\n<td align=\"left\">2013-11-21<\/td>\n<td align=\"left\">Fixed the problem reported by Mihai Todor at line 300 in <code>cipher.cc<\/code>.<\/td>\n<\/tr>\n<tr>\n<td align=\"right\">1.1<\/td>\n<td align=\"left\">2012-09-22<\/td>\n<td align=\"left\">Fixed a valgrind problem at line 298 in cipher.cc as reported by an anonymous user.<\/td>\n<\/tr>\n<tr>\n<td align=\"right\">1.0<\/td>\n<td align=\"left\">2012-02-14<\/td>\n<td align=\"left\">Initial release with source links corrected as reported by nvanwyen.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h1>1 Downloads<\/h1>\n<p>You can download the source code in the following formats:<\/p>\n<div style=\"margin-left: 20px;\">\n<table>\n<thead>\n<tr>\n<th>File<\/th>\n<th>Size<\/th>\n<th>Check Sum<\/th>\n<th>Uncompress Command<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\"><a href=\"http:\/\/projects.joelinoff.com\/cipher\/cipher-1.2\/cipher-1.2.tar.bz2\">cipher-1.2.tar.bz2<\/a><\/td>\n<td align=\"right\">15K<\/td>\n<td align=\"right\">17148<\/td>\n<td align=\"left\">tar jxf cipher-1.2.tar.bz2<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"http:\/\/projects.joelinoff.com\/cipher\/cipher-1.2\/cipher-1.2.tar.gz\">cipher-1.2.tar.gz<\/a><\/td>\n<td align=\"right\">16K<\/td>\n<td align=\"right\">29380<\/td>\n<td align=\"left\">tar zxf cipher-1.2.tar.gz<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"http:\/\/projects.joelinoff.com\/cipher\/cipher-1.2\/cipher-1.2.zip\">cipher-1.2.zip<\/a><\/td>\n<td align=\"right\">19K<\/td>\n<td align=\"right\">1134<\/td>\n<td align=\"left\">unzip cipher-1.2.zip<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h1>2 Build and Test<\/h1>\n<p>To build and test the project type <code>make<\/code>. You must have the openssl headers installed.<\/p>\n<ol>\n<li>On CentOS you can install the openssl headers by running &#8220;<code>yum install openssl-devel<\/code>&#8220;.<\/li>\n<li>On cygwin you must download the openssl development package.<\/li>\n<li>On Ubuntu you can install it by running &#8220;<code>apt-get install openssl libssl-dev<\/code>&#8220;.<\/li>\n<\/ol>\n<p>It uses the g++ compiler and has been tested on CentOS 5.5, CentOS 6.4, Ubuntu 11.04, cygwin and Mac OS X 10.9.<\/p>\n<h2>2.1 Source Files<\/h2>\n<p>Here is the list of source files.<\/p>\n<table>\n<thead>\n<tr>\n<th>File<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>a.h<\/td>\n<td>Doxygen main-page.<\/td>\n<\/tr>\n<tr>\n<td>cipher.cc<\/td>\n<td>Class implementation.<\/td>\n<\/tr>\n<tr>\n<td>cipher.h<\/td>\n<td>Class interface.<\/td>\n<\/tr>\n<tr>\n<td>ct.cc<\/td>\n<td>Tool that allows you to use the class.<\/td>\n<\/tr>\n<tr>\n<td>doxygen.cfg<\/td>\n<td>Doxygen configuration file.<\/td>\n<\/tr>\n<tr>\n<td>Makefile<\/td>\n<td>Makefile.<\/td>\n<\/tr>\n<tr>\n<td>test.cc<\/td>\n<td>Tester.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>3 ct<\/h1>\n<p>Once it is built there will be a tool called ct.exe. It uses the Cipher class to allow you to encrypt and decrypt files and strings. Type <code>.\/ct.exe -h<\/code> to get information about how to use the tool.<\/p>\n<h2>3.1 Example<\/h2>\n<p>The following example shows how to use the ct program.<br \/>\n[crayon lang=&#8221;bash&#8221; toolbar=&#8221;always&#8221; title=&#8221;Run ct&#8221;]<br \/>\n% # Encrypt stdin to stdout<br \/>\n% echo &#8216;Lorem ipsum dolor sit amet&#8217; | .\/ct.exe -e<br \/>\nU2FsdGVkX19nxmlzUf9K7K0Z40ZlovVWSfndp4VHLKSl9j5FXuvHi7dz08nVDsrV<br \/>\n% # Decrypt stdin to stdout<br \/>\n% echo U2FsdGVkX19nxmlzUf9K7K0Z40ZlovVWSfndp4VHLKSl9j5FXuvHi7dz08nVDsrV \\<br \/>\n| .\/ct.exe -d<br \/>\nLorem ipsum dolor sit amet<br \/>\n[\/crayon]<\/p>\n<h2>3.2 Help<\/h2>\n<p>Here is the program help.<br \/>\n[crayon lang=&#8221;bash&#8221; toolbar=&#8221;always&#8221; title=&#8221;Help&#8221;]<br \/>\nNAME<br \/>\nct &#8211; Cipher tool that used to encrypt or decrypt files.<\/p>\n<p>SYNOPSIS<br \/>\nct [OPTIONS]<\/p>\n<p>DESCRIPTION<br \/>\nEncrypt or decrypt a file.<\/p>\n<p>OPTIONS<br \/>\n-c Count of number of init rounds.<\/p>\n<p>-C The name of the cipher to use (ex. aes-256-cbc).<\/p>\n<p>&#8211;d Decrypt.<\/p>\n<p>-D The name of the digest to use (ex. sha1).<\/p>\n<p>&#8211;debug Turn on internal debugging.<\/p>\n<p>&#8211;e Encrypt.<\/p>\n<p>-h This help message.<\/p>\n<p>-i Input file.<\/p>\n<p>-o Output file.<\/p>\n<p>-p Passphrase.<\/p>\n<p>-s Salt as a string.<\/p>\n<p>-x Salt as hex digits (16)..<\/p>\n<p>-v Increase the level of verbosity.<\/p>\n<p>-V Print the version number and exit.<\/p>\n<p>EXAMPLES<br \/>\n% # Help<br \/>\n% .\/ct.exe -h<\/p>\n<p>% # Encrypt stdin to stdout<br \/>\n% echo &#8216;Lorem ipsum dolor sit amet&#8217; | .\/ct.exe -e<br \/>\nU2FsdGVkX19nxmlzUf9K7K0Z40ZlovVWSfndp4VHLKSl9j5FXuvHi7dz08nVDsrV<\/p>\n<p>% # Decrypt stdin to stdout<br \/>\n% echo U2FsdGVkX19nxmlzUf9K7K0Z40ZlovVWSfndp4VHLKSl9j5FXuvHi7dz08nVDsrV | .\/ct.exe -d<br \/>\nLorem ipsum dolor sit amet<\/p>\n<p>% # Encrypt a file<br \/>\n% # It is okay to reference the same file.<br \/>\n% .\/ct.exe -e -p &#8216;Tally Ho!&#8217; -i foo.txt -o foo.txt<\/p>\n<p>% # Decrypt a file<br \/>\n% # It is okay to reference the same file.<br \/>\n% .\/ct.exe -d -p &#8216;Tally Ho!&#8217; -i foo.txt -o foo.txt<\/p>\n<p>AUTHOR<br \/>\nJoe Linoff<br \/>\n[\/crayon]<\/p>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have developed a class named Cipher that allows you to encrypt and decrypt files or strings using the OpenSSL AES-256-CBC cipher and SHA1 digest algorithms. It is interoperable with the openssl command line tool which makes it a good introduction to using OpenSSL for ciphers. The project has been moved to github: https:\/\/github.com\/jlinoff\/openssl-aes-cipher. The &hellip; <a href=\"https:\/\/joelinoff.com\/blog\/?p=664\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">C++ class that interfaces to OpenSSL ciphers<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[37,5],"tags":[],"_links":{"self":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/664"}],"collection":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=664"}],"version-history":[{"count":40,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/664\/revisions"}],"predecessor-version":[{"id":1757,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/664\/revisions\/1757"}],"wp:attachment":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=664"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}