<?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>devedup.com &#187; php</title>
	<atom:link href="http://blog.devedup.com/index.php/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.devedup.com</link>
	<description></description>
	<lastBuildDate>Sun, 09 Oct 2011 16:00:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>MD5 in Java (&#8230; and Ruby &amp; PHP)</title>
		<link>http://blog.devedup.com/index.php/2009/06/07/md5-in-java/</link>
		<comments>http://blog.devedup.com/index.php/2009/06/07/md5-in-java/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 22:43:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[md5]]></category>

		<guid isPermaLink="false">http://blog.devedup.com/?p=57</guid>
		<description><![CDATA[Why doesn&#8217;t the standard Java SDK provide a method that returns a 32 character (128bit) String representation of  an MD5 encrypted string&#8230; just like most other languages do (PHP, Ruby)&#8230; i don&#8217;t know! Below are Ruby and PHP examples and then a Java implementation. Ruby implementation: require 'digest/md5' digest = Digest::MD5.hexdigest(&#34;encrypt this text&#34;) PHP implementation: [...]]]></description>
			<content:encoded><![CDATA[<p>Why doesn&#8217;t the standard Java SDK provide a method that returns a 32 character (128bit) String representation of  an MD5 encrypted string&#8230; just like most other languages do (PHP, Ruby)&#8230; i don&#8217;t know! Below are Ruby and PHP examples and then a Java implementation.</p>
<p>Ruby implementation:</p>
<pre class="brush: ruby;">require 'digest/md5'
digest = Digest::MD5.hexdigest(&quot;encrypt this text&quot;)</pre>
<p>PHP implementation:</p>
<pre class="brush: php;">&lt;?php
   $str = &quot;Hello&quot;;
   echo md5($str);
?&gt;</pre>
<p>Java implementation (2 methods for clarity):</p>
<pre class="brush: java;">import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.io.UnsupportedEncodingException

public class MD5 {

public static String digest(String text) {
      throws NoSuchAlgorithmException, UnsupportedEncodingException {
   MessageDigest md = MessageDigest.getInstance(&quot;MD5&quot;);
   byte[] md5hash = new byte[32];
   md.update(text.getBytes(&quot;iso-8859-1&quot;), 0, text.length());
   md5hash = md.digest();
   return convertToHex(md5hash);
}

private static String convertToHex(byte[] b) {
   StringBuilder result = new StringBuilder(32);
   for (int i = 0; i &amp;lt; b.length; i++) {
      result.append(
         Integer.toString( ( b[i] &amp;amp; 0xff ) + 0x100, 16).substring( 1 ));
   }
   return result.toString();
}
}</pre>
<p>This isn&#8217;t the fastest MD5 implementation, but that isn&#8217;t my goal here. I found quite a few implementations when searching, some of which gave results which were not even correct!</p>
<p>Hope this implementation helps someone else.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.devedup.com/index.php/2009/06/07/md5-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

