{"id":664,"date":"2012-04-07T19:45:37","date_gmt":"2012-04-07T19:45:37","guid":{"rendered":"http:\/\/joelinoff.com\/blog\/?p=664"},"modified":"2026-06-28T17:38:26","modified_gmt":"2026-06-29T00:38:26","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":"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.\n\nThe 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.\n\nI 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.\n<!--more-->\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>\nYou can download the source code in the following formats:\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>\nTo build and test the project type <code>make<\/code>. You must have the openssl headers installed.\n<ol>\n \t<li>On CentOS you can install the openssl headers by running &#8220;<code>yum install openssl-devel<\/code>&#8220;.<\/li>\n \t<li>On cygwin you must download the openssl development package.<\/li>\n \t<li>On Ubuntu you can install it by running &#8220;<code>apt-get install openssl libssl-dev<\/code>&#8220;.<\/li>\n<\/ol>\nIt 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.\n<h2>2.1 Source Files<\/h2>\nHere is the list of source files.\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>\nOnce 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.\n<h2>3.1 Example<\/h2>\nThe following example shows how to use the ct program.\n\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\">% # Encrypt stdin to stdout\n% echo 'Lorem ipsum dolor sit amet' | .\/ct.exe -e\nU2FsdGVkX19nxmlzUf9K7K0Z40ZlovVWSfndp4VHLKSl9j5FXuvHi7dz08nVDsrV\n% # Decrypt stdin to stdout\n% echo U2FsdGVkX19nxmlzUf9K7K0Z40ZlovVWSfndp4VHLKSl9j5FXuvHi7dz08nVDsrV \\\n| .\/ct.exe -d\nLorem ipsum dolor sit amet<\/code><\/pre>\n\n<h2>3.2 Help<\/h2>\nHere is the program help.\n\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\">NAME\nct - Cipher tool that used to encrypt or decrypt files.\n\nSYNOPSIS\nct [OPTIONS]\n\nDESCRIPTION\nEncrypt or decrypt a file.\n\nOPTIONS\n-c Count of number of init rounds.\n\n-C The name of the cipher to use (ex. aes-256-cbc).\n\n--d Decrypt.\n\n-D The name of the digest to use (ex. sha1).\n\n--debug Turn on internal debugging.\n\n--e Encrypt.\n\n-h This help message.\n\n-i Input file.\n\n-o Output file.\n\n-p Passphrase.\n\n-s Salt as a string.\n\n-x Salt as hex digits (16)..\n\n-v Increase the level of verbosity.\n\n-V Print the version number and exit.\n\nEXAMPLES\n% # Help\n% .\/ct.exe -h\n\n% # Encrypt stdin to stdout\n% echo 'Lorem ipsum dolor sit amet' | .\/ct.exe -e\nU2FsdGVkX19nxmlzUf9K7K0Z40ZlovVWSfndp4VHLKSl9j5FXuvHi7dz08nVDsrV\n\n% # Decrypt stdin to stdout\n% echo U2FsdGVkX19nxmlzUf9K7K0Z40ZlovVWSfndp4VHLKSl9j5FXuvHi7dz08nVDsrV | .\/ct.exe -d\nLorem ipsum dolor sit amet\n\n% # Encrypt a file\n% # It is okay to reference the same file.\n% .\/ct.exe -e -p 'Tally Ho!' -i foo.txt -o foo.txt\n\n% # Decrypt a file\n% # It is okay to reference the same file.\n% .\/ct.exe -d -p 'Tally Ho!' -i foo.txt -o foo.txt\n\nAUTHOR\nJoe Linoff<\/code><\/pre>\n\n\nEnjoy!\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,"footnotes":""},"categories":[37,5],"tags":[],"class_list":["post-664","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-programming"],"_links":{"self":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/664","targetHints":{"allow":["GET"]}}],"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":41,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/664\/revisions"}],"predecessor-version":[{"id":1790,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/664\/revisions\/1790"}],"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}]}}