<?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; MD5</title>
	<atom:link href="http://silveiraneto.net/tag/md5/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>Gravatar with JavaFX</title>
		<link>http://silveiraneto.net/2008/12/21/gravatar-with-javafx/</link>
		<comments>http://silveiraneto.net/2008/12/21/gravatar-with-javafx/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 23:26:12 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Avatar]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[Gravatar]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[MD5]]></category>
		<category><![CDATA[MD5sum]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[vídeo]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=1974</guid>
		<description><![CDATA[Gravatar is easy way to put global recognized avatar images into any Internet application. Gravatar would stands for globally recognized avatar. Below,  the Java class that I got from the Gravatar Java reference. Here is a static class called md5 that applies a MD5Sum algorithm over a string. Is a little complex code but all [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://gravatar.com">Gravatar</a> is easy way to put global recognized avatar images into any Internet application. Gravatar would stands for <em>globally recognized avatar</em>.</p>
<p style="text-align: center;"><object width="656" height="320" data="http://www.youtube.com/v/VCJeqVkb4bw&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/VCJeqVkb4bw&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /></object></p>
<p>Below,  the Java class that I got from the <a title="Gravatar in Java" href="http://en.gravatar.com/site/implement/java">Gravatar Java reference</a>. Here is a static class called <em>md5</em> that applies a MD5Sum algorithm over a string. Is a little complex code but all behavior keeps encapsulated and who uses it don&#8217;t need to know how it works. Just gives a string and receives a encrypted string. Those two codes are also a good example of how calling Java classes inside a JavaFX code.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">gravatarexample</span>;
&nbsp;
<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.io.UnsupportedEncodingException</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> MD5 <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: #003399;">String</span> toHex<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
         <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;MD5&quot;</span><span style="color: #009900;">&#41;</span>;
         <span style="color: #000066; font-weight: bold;">byte</span> array<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> md.<span style="color: #006633;">digest</span><span style="color: #009900;">&#40;</span>message.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;CP1252&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
         <span style="color: #003399;">StringBuffer</span> sb <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;">&amp;</span>lt; array.<span style="color: #006633;">length</span>; <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            sb.<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><span style="color: #009900;">&#40;</span>array<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&amp;</span>amp;0xFF<span style="color: #009900;">&#41;</span>|0x100<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">return</span> sb.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">NoSuchAlgorithmException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">UnsupportedEncodingException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span>;
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>As a Java class in the same package, any JavaFX (or Java) code can call it without any problem. Just to keep the code more clear I&#8217;m importing it explicitly. Is this example I also create some Swing interface to give user the option to put his mail, adjust the image size and get a output direct link or html image tag.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">gravatarexample</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">gravatarexample.MD5</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.ext.swing.SwingButton</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.ext.swing.SwingSlider</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.ext.swing.SwingTextField</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.image.Image</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.image.ImageView</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.layout.VBox</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Scene</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.stage.Stage</span>;
&nbsp;
var mail <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Email&quot;</span>;
var key <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span>;
&nbsp;
function gravatalize<span style="color: #009900;">&#40;</span>mail<span style="color: #339933;">:</span><span style="color: #003399;">String</span>, size<span style="color: #339933;">:</span> <span style="color: #003399;">Integer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #003399;">String</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;http://www.gravatar.com/avatar/{MD5.toHex(mail)}?s={size}&quot;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var inputtxt <span style="color: #339933;">=</span> SwingTextField <span style="color: #009900;">&#123;</span>
   columns<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span>
   text<span style="color: #339933;">:</span> mail
<span style="color: #009900;">&#125;</span>
&nbsp;
var slider <span style="color: #339933;">=</span> SwingSlider <span style="color: #009900;">&#123;</span>
   minimum<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span>
   maximum<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span>
   value<span style="color: #339933;">:</span> <span style="color: #cc66cc;">100</span>
   vertical<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">false</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var button <span style="color: #339933;">=</span> SwingButton <span style="color: #009900;">&#123;</span>
   text<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Get Gravatar&quot;</span>
   action<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      key <span style="color: #339933;">=</span> gravatalize<span style="color: #009900;">&#40;</span>inputtxt.<span style="color: #006633;">text</span>, slider.<span style="color: #006633;">value</span><span style="color: #009900;">&#41;</span>;
      directoutput.<span style="color: #006633;">text</span> <span style="color: #339933;">=</span> key;
      htmloutput.<span style="color: #006633;">text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;img src=&quot;</span><span style="color: #009900;">&#123;</span>key<span style="color: #009900;">&#125;</span><span style="color: #0000ff;">&quot; alt=&quot;</span>\<span style="color: #339933;">&amp;</span>quot;gravatar\<span style="color: #339933;">&amp;</span>quot;<span style="color: #0000ff;">&quot; /&gt;&quot;</span>;
      photo.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>
         backgroundLoading<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>,
         url<span style="color: #339933;">:</span> key<span style="color: #009900;">&#125;</span>;
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var photo<span style="color: #339933;">:</span>ImageView <span style="color: #339933;">=</span> ImageView <span style="color: #009900;">&#123;</span>
   image<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">null</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var directoutput <span style="color: #339933;">=</span> SwingTextField <span style="color: #009900;">&#123;</span>
   columns<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span>
   text<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;direct link image&quot;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
var htmloutput <span style="color: #339933;">=</span> SwingTextField <span style="color: #009900;">&#123;</span>
   columns<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span>
   text<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;html tag image&quot;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
Stage <span style="color: #009900;">&#123;</span>
   title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Gravatar&quot;</span>
   width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">300</span>
   height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">340</span>
   scene<span style="color: #339933;">:</span> Scene <span style="color: #009900;">&#123;</span>
      content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
         VBox <span style="color: #009900;">&#123;</span>
            spacing<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span>
            content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>inputtxt, slider, button, directoutput, htmloutput, photo<span style="color: #009900;">&#93;</span>
         <span style="color: #009900;">&#125;</span>,
      <span style="color: #009900;">&#93;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>The string itself is assembled in the <em>gravatalize</em> function. You give a mail and it&#8217;s returns a Gravatar direct link to the image. There&#8217;s many cool ways to use together Gravatar and a JavaFX Internet application.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/12/21/gravatar-with-javafx/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
	</channel>
</rss>

