<?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>Silveira Neto &#187; Criptografia</title>
	<atom:link href="http://silveiraneto.net/tag/criptografia/feed/" rel="self" type="application/rss+xml" />
	<link>http://silveiraneto.net</link>
	<description></description>
	<lastBuildDate>Fri, 09 Mar 2012 04:13:27 +0000</lastBuildDate>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>SHA-1 em Java</title>
		<link>http://silveiraneto.net/2008/01/07/sha-1-em-java/</link>
		<comments>http://silveiraneto.net/2008/01/07/sha-1-em-java/#comments</comments>
		<pubDate>Mon, 07 Jan 2008 04:41:59 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Criptografia]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[MD5sum]]></category>
		<category><![CDATA[MessageDigest]]></category>
		<category><![CDATA[SHA]]></category>
		<category><![CDATA[SHA-1]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/2008/01/07/sha-1-em-java/</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2008/01/07/sha-1-em-java/" title="SHA-1 em Java"></a>import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; &#160; public class sha1it &#123; public static void main&#40;String&#91;&#93; args&#41; throws NoSuchAlgorithmException &#123; if &#40;args.length==0&#41; return; &#160; MessageDigest md = MessageDigest.getInstance&#40;&#34;SHA1&#34;&#41;; md.update&#40;args&#91;0&#93;.getBytes&#40;&#41;&#41;; byte&#91;&#93; newHash = md.digest&#40;&#41;; StringBuffer newHashStringBuffer = new StringBuffer&#40;&#41;; for &#40; int i = &#8230;<p class="read-more"><a href="http://silveiraneto.net/2008/01/07/sha-1-em-java/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2008/01/07/sha-1-em-java/" title="SHA-1 em Java"></a>
<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.MessageDigest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.NoSuchAlgorithmException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> sha1it <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">NoSuchAlgorithmException</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>args.<span style="color: #006633;">length</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">MessageDigest</span> md <span style="color: #339933;">=</span> <span style="color: #003399;">MessageDigest</span>.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SHA1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        md.<span style="color: #006633;">update</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> newHash <span style="color: #339933;">=</span> md.<span style="color: #006633;">digest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">StringBuffer</span> newHashStringBuffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> newHash.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span>
            newHashStringBuffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">toHexString</span><span style="color: #009900;">&#40;</span>newHash<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&amp;</span>0xff<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>newHashStringBuffer.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Vai calcular o <a href="http://pt.wikipedia.org/wiki/Sha1">SHA-1</a> do primeiro argumento da linha de comando:</p>
<blockquote><p>$ java sha1it silveira<br />
665fc8e2ed1b8aa1571a5c9d3e14d89bad4f0
</p></blockquote>
<p><small>Note que não é uma implementação pura do SHA-1. Simplesmente pedimos por essa implementação, que pode não estar disponível.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/01/07/sha-1-em-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SHA1 em Python</title>
		<link>http://silveiraneto.net/2007/08/27/sha1-em-python/</link>
		<comments>http://silveiraneto.net/2007/08/27/sha1-em-python/#comments</comments>
		<pubDate>Tue, 28 Aug 2007 01:20:03 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[Criptografia]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/2007/08/27/sha1-em-python/</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2007/08/27/sha1-em-python/" title="SHA1 em Python"></a>Calcular o SHA1 de uma string em Python é feito quase da mesma forma do calculo do md5 que eu já mostrei aqui antes. A partir da versão do Python 2.5 a maneira correta de se fazer é assim: import &#8230;<p class="read-more"><a href="http://silveiraneto.net/2007/08/27/sha1-em-python/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2007/08/27/sha1-em-python/" title="SHA1 em Python"></a><p>Calcular o SHA1 de uma string em Python é feito quase da mesma forma do calculo do <a href="http://silveiraneto.net/2007/08/26/funcao-md5-em-python/">md5 que eu já mostrei aqui antes</a>.</p>
<p>A partir da versão do Python 2.5 a maneira correta de se fazer é assim:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> hashlib
<span style="color: #ff7700;font-weight:bold;">print</span> hashlib.<span style="color: black;">sha1</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Silveira'</span><span style="color: black;">&#41;</span>.<span style="color: black;">hexdigest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Isso vai imprimir isto:</p>
<blockquote><p>25e58a0147633e39c2a2fcceff9a13a181e672b9</p></blockquote>
<p>Para fazer o calculo do MD5, também se usa a hashlib:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> hashlib
<span style="color: #ff7700;font-weight:bold;">print</span> hashlib.<span style="color: #dc143c;">md5</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Silveira'</span><span style="color: black;">&#41;</span>.<span style="color: black;">hexdigest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Que vai nos dar o md5 da string &#8216;Silveira&#8217;:</p>
<blockquote><p>43eb9e4547c642db6cd19713b5c1dff2</p></blockquote>
<p>O módulo hashlib possui os contrutores md5(), sha1(), sha224(), sha256(), sha384(), e sha512(). Dependendo da implementação da OpenSSL que você tem instalada você poderá ganhar alguns outros construtores.</p>
<p>Maiores informações: <a href="http://docs.python.org/lib/module-hashlib.html">documentação da hashlib</a></p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2007/08/27/sha1-em-python/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Função MD5 em Python</title>
		<link>http://silveiraneto.net/2007/08/26/funcao-md5-em-python/</link>
		<comments>http://silveiraneto.net/2007/08/26/funcao-md5-em-python/#comments</comments>
		<pubDate>Sun, 26 Aug 2007 22:58:42 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[Criptografia]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/2007/08/26/funcao-md5-em-python/</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2007/08/26/funcao-md5-em-python/" title="Função MD5 em Python"></a>MD5, Message-Digest algorithm 5, é um algoritmo de hash de 128 bits, unidirecional. Ele é muito útil como método de verificação de integridade de arquivos, armazenamento de senhas, criptografia ou para hashing em geral. Eu utilizo ele com muita frequência. &#8230;<p class="read-more"><a href="http://silveiraneto.net/2007/08/26/funcao-md5-em-python/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2007/08/26/funcao-md5-em-python/" title="Função MD5 em Python"></a><p><a href="http://pt.wikipedia.org/wiki/MD5">MD5</a>, Message-Digest algorithm 5, é um algoritmo de hash de 128 bits, unidirecional. Ele é muito útil como método de verificação de integridade de arquivos, armazenamento de senhas, criptografia ou para hashing em geral. Eu utilizo ele com muita frequência.</p>
<p>Em Python você calcula o hash de uma string em duas linhas:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">md5</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">md5</span>.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'silveira'</span><span style="color: black;">&#41;</span>.<span style="color: black;">hexdigest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>O md5.new() retorna um objeto que cria md5. Ele é bem flexível e pode ser utilizado várias vezes. O hexdigest é a representação hexadecimal do md5, aquela que pode ser impressa.</p>
<p>Esse código imprime isso:</p>
<blockquote><p>3df2175295d900d6f0c2f3a521d957cd</p></blockquote>
<p>Que é o md5 de silveira.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2007/08/26/funcao-md5-em-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

