<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>langui.sh &#187; aes</title>
	<atom:link href="http://langui.sh/tag/aes/feed/" rel="self" type="application/rss+xml" />
	<link>http://langui.sh</link>
	<description>Fun hacks, WP plugins, photography, and PKI junk.  Languishing since 2008.</description>
	<lastBuildDate>Tue, 17 Jan 2012 20:23:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>RSA Encryption and Signing</title>
		<link>http://langui.sh/2009/03/21/rsa-encryption-and-signing/</link>
		<comments>http://langui.sh/2009/03/21/rsa-encryption-and-signing/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 04:02:51 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[aes]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[rsa]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=440</guid>
		<description><![CDATA[<a href="http://langui.sh/2009/03/21/rsa-encryption-and-signing/" title="RSA Encryption and Signing"></a>OpenSSL provides several tools that allow you to RSA encrypt/sign arbitrary data files. Of course, directly RSA encrypting large volumes of data is impractical because the encrypted/signed data cannot exceed the size of the key material. This is one of &#8230;<p class="read-more"><a href="http://langui.sh/2009/03/21/rsa-encryption-and-signing/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://langui.sh/2009/03/21/rsa-encryption-and-signing/" title="RSA Encryption and Signing"></a><p>OpenSSL provides several tools that allow you to RSA encrypt/sign arbitrary data files.  Of course, directly RSA encrypting large volumes of data is impractical because the encrypted/signed data cannot exceed the size of the key material.  This is one of the reasons why SSL connections typically handshake and then pass an AES (or RC4, et cetera) key to do symmetric encryption thereafter.<sup class='footnote'><a href='#fn-440-1' id='fnref-440-1'>1</a></sup></p>
<p>Generate a private key. You can change the last number to the preferred modulus size.  Keys greater than 4096-bit will take a long time to generate.<sup class='footnote'><a href='#fn-440-2' id='fnref-440-2'>2</a></sup></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl genrsa <span style="color: #660033;">-out</span> private.pem <span style="color: #000000;">4096</span></pre></div></div>

<p>With the private key we can now encrypt the data.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl rsautl <span style="color: #660033;">-encrypt</span> <span style="color: #660033;">-inkey</span> private.pem <span style="color: #660033;">-in</span> publicfile <span style="color: #660033;">-out</span> privatefile</pre></div></div>

<p>To decrypt just reverse it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl rsautl <span style="color: #660033;">-decrypt</span> <span style="color: #660033;">-inkey</span> private.pem <span style="color: #660033;">-in</span> privatefile <span style="color: #660033;">-out</span> publicfile</pre></div></div>

<p>If you would rather sign the data&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl rsautl <span style="color: #660033;">-sign</span> <span style="color: #660033;">-inkey</span> private.pem <span style="color: #660033;">-in</span> filetosign <span style="color: #660033;">-out</span> signed_data</pre></div></div>

<p>To verify the signature just use -verify.<sup class='footnote'><a href='#fn-440-3' id='fnref-440-3'>3</a></sup></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl rsautl <span style="color: #660033;">-verify</span> <span style="color: #660033;">-inkey</span> private.pem <span style="color: #660033;">-in</span> signed_data</pre></div></div>

<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-440-1'>Another big reason is speed.  AES is much, much faster than RSA. <span class='footnotereverse'><a href='#fnref-440-1'>&#8617;</a></span></li>
<li id='fn-440-2'>If you attempt to encrypt or sign data larger than your key length allows, you will receive an error similar to this: 23465:error:0406D06E:rsa routines:RSA_padding_add_PKCS1_type_2:data too large for key size:rsa_pk1.c:151: <span class='footnotereverse'><a href='#fnref-440-2'>&#8617;</a></span></li>
<li id='fn-440-3'>You can also use -hexdump or -raw to view the data in those forms. <span class='footnotereverse'><a href='#fnref-440-3'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/03/21/rsa-encryption-and-signing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AES Encryption Via OpenSSL</title>
		<link>http://langui.sh/2009/01/31/aes-encryption-via-openssl/</link>
		<comments>http://langui.sh/2009/01/31/aes-encryption-via-openssl/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 04:46:18 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[aes]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[openssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=146</guid>
		<description><![CDATA[<a href="http://langui.sh/2009/01/31/aes-encryption-via-openssl/" title="AES Encryption Via OpenSSL"></a>If you have ever wanted to encrypt a blob of data for transmission or archival, OpenSSL provides a simple way to accomplish this task without resorting to platform specific tools. To encrypt1: openssl enc -e -aes-256-cbc -in filename -out filename.enc &#8230;<p class="read-more"><a href="http://langui.sh/2009/01/31/aes-encryption-via-openssl/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://langui.sh/2009/01/31/aes-encryption-via-openssl/" title="AES Encryption Via OpenSSL"></a><p>If you have ever wanted to encrypt a blob of data for transmission or archival, OpenSSL provides a simple way to accomplish this task without resorting to platform specific tools.<br />
To encrypt<sup class='footnote'><a href='#fn-146-1' id='fnref-146-1'>1</a></sup>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl enc <span style="color: #660033;">-e</span> <span style="color: #660033;">-aes-256-cbc</span> <span style="color: #660033;">-in</span> filename <span style="color: #660033;">-out</span> filename.enc</pre></div></div>

<p>To decrypt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl enc <span style="color: #660033;">-d</span> <span style="color: #660033;">-aes-256-cbc</span> <span style="color: #660033;">-in</span> filename.enc <span style="color: #660033;">-out</span> filename.dec</pre></div></div>

<p>The example above uses AES256 in cipher block chaining mode, however there are almost 50 different cipher functions available for encryption.  To see a list, just type openssl enc help.  I would very seriously recommend staying with well-known and accepted standard ciphers like AES unless you have an explicit need to choose something more esoteric.</p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-146-1'>You can also add -a to encode to base64 so you can easily send via email or other methods that don&#8217;t support binary encoding. <span class='footnotereverse'><a href='#fnref-146-1'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/01/31/aes-encryption-via-openssl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using memcached
Page Caching using memcached
Database Caching 7/21 queries in 0.007 seconds using memcached
Object Caching 519/537 objects using memcached

Served from: langui.sh @ 2012-02-07 06:26:42 -->
