<?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; SHA-1</title>
	<atom:link href="http://silveiraneto.net/tag/sha-1/feed/" rel="self" type="application/rss+xml" />
	<link>http://silveiraneto.net</link>
	<description>the world is a pixel</description>
	<lastBuildDate>Sun, 08 Jan 2012 05:17:57 +0000</lastBuildDate>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</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[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 = 0; i &#60; newHash.length; i++ &#41; newHashStringBuffer.append&#40;Integer.toHexString&#40;newHash&#91;i&#93;&#38;0xff&#41;&#41;; System.out.println&#40;newHashStringBuffer.toString&#40;&#41;&#41;; &#125; &#125; Vai calcular o SHA-1 do [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_syntax">
<div class="code">
<pre class="java 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: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.NoSuchAlgorithmException</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>0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</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>;
        md.<span style="color: #006633;">update</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span>0<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: #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: #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: #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> 0; i <span style="color: #339933;">&lt;</span> newHash.<span style="color: #006633;">length</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: #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: #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>
	</channel>
</rss>

