<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: PHP MD5 not the same as .NET MD5</title>
	<atom:link href="http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/feed/" rel="self" type="application/rss+xml" />
	<link>http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/</link>
	<description>OKCOOL make cool digital applications. We help companies balance brand and technology. From mashups to mobile shennanigans to social networks.</description>
	<lastBuildDate>Tue, 16 Mar 2010 08:21:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Amrox</title>
		<link>http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/comment-page-1/#comment-1187</link>
		<dc:creator>Amrox</dc:creator>
		<pubDate>Sun, 14 Dec 2008 18:51:26 +0000</pubDate>
		<guid isPermaLink="false">http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/#comment-1187</guid>
		<description>I think UTF7 is not the answer!!!
I am using Arabic (I think the problem will be there for other languages)
I am trying to build a login based on VBulletin its working for English but Arabic its not working I tried all types of encoding:
(its with Arabic Windows encoding &quot;windows-1256&quot;&quot;)
The following code comparing the DB password and the hashed password they should match:
//&quot;y)@&quot; is the salt

           string password = &quot;كودلاب&quot;;
            foreach (EncodingInfo enc1 in Encoding.GetEncodings())
                foreach (EncodingInfo enc2 in Encoding.GetEncodings())
                    //foreach (EncodingInfo enc3 in list3)
                        if (Md5Hash(Md5Hash(password, enc1.GetEncoding()) + &quot;y)@&quot;, enc2.GetEncoding()) == &quot;acfae8024d61fe3697203fbf0fc6e6ed&quot;)
                            MessageBox.Show(enc1.Name + &quot; - &quot; + enc2.Name);

Can anybody help</description>
		<content:encoded><![CDATA[<p>I think UTF7 is not the answer!!!<br />
I am using Arabic (I think the problem will be there for other languages)<br />
I am trying to build a login based on VBulletin its working for English but Arabic its not working I tried all types of encoding:<br />
(its with Arabic Windows encoding &#8220;windows-1256&#8243;&#8221;)<br />
The following code comparing the DB password and the hashed password they should match:<br />
//&#8221;y)@&#8221; is the salt</p>
<p>           string password = &#8220;كودلاب&#8221;;<br />
            foreach (EncodingInfo enc1 in Encoding.GetEncodings())<br />
                foreach (EncodingInfo enc2 in Encoding.GetEncodings())<br />
                    //foreach (EncodingInfo enc3 in list3)<br />
                        if (Md5Hash(Md5Hash(password, enc1.GetEncoding()) + &#8220;y)@&#8221;, enc2.GetEncoding()) == &#8220;acfae8024d61fe3697203fbf0fc6e6ed&#8221;)<br />
                            MessageBox.Show(enc1.Name + &#8221; &#8211; &#8221; + enc2.Name);</p>
<p>Can anybody help</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MD5 in PHP works exactly as it should (don&#8217;t believe the hype!) &#124; Thomas David Wright</title>
		<link>http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/comment-page-1/#comment-577</link>
		<dc:creator>MD5 in PHP works exactly as it should (don&#8217;t believe the hype!) &#124; Thomas David Wright</dc:creator>
		<pubDate>Mon, 04 Aug 2008 13:16:00 +0000</pubDate>
		<guid isPermaLink="false">http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/#comment-577</guid>
		<description>[...] don&#8217;t pay any heed whatsoever to the whisperings that abound the wonderful interweb. Hmmm&#8230; Maybe &#8216;abound&#8217; isn&#8217;t the right [...]</description>
		<content:encoded><![CDATA[<p>[...] don&#8217;t pay any heed whatsoever to the whisperings that abound the wonderful interweb. Hmmm&#8230; Maybe &#8216;abound&#8217; isn&#8217;t the right [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/comment-page-1/#comment-566</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Fri, 18 Jul 2008 12:31:54 +0000</pubDate>
		<guid isPermaLink="false">http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/#comment-566</guid>
		<description>Thanks for everyone&#039;s comments. I understand the problem much better now. I&#039;ve experienced problems as suggested with UTF7 but have used the UTF8 encoding and at the moment it seems to be working.</description>
		<content:encoded><![CDATA[<p>Thanks for everyone&#8217;s comments. I understand the problem much better now. I&#8217;ve experienced problems as suggested with UTF7 but have used the UTF8 encoding and at the moment it seems to be working.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RyanTheGreat</title>
		<link>http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/comment-page-1/#comment-534</link>
		<dc:creator>RyanTheGreat</dc:creator>
		<pubDate>Wed, 11 Jun 2008 02:39:08 +0000</pubDate>
		<guid isPermaLink="false">http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/#comment-534</guid>
		<description>I&#039;m not a .NET programmer, but I may be able to address a few of the comments here. Starting with the article itself, I don&#039;t believe that UTF-7 is the actual answer to your problems, but rather, a means of consistency for the data encoding before encryption. When computing a hash from a string, the data encoding is only important as to the extent of consistency in characters. What I mean by this is, if a string is being transmitted encoded as UTF-8 encrypted by md5 and compared against a ISO-8859-1 encoded string with the same characters it may or may not be equal due to the encoding, converting the strings in this example to UTF-7 is just a means of ensuring they are represented equivalently.

As for the comment by victorantos, the reason your output is not equivalent to php&#039;s md5 without even knowing any .NET C# syntax is clear from the function call. HMAC-md5 (or any other HMAC-hash function) provides an additional functionality above the basic md5 hashing algorithm. The HMAC- algorithms are frequently used in API&#039;s in which the transmitting parties share a secret key K and hash the data along with XORing K against  2 sets of data to explain simply. The basic explanation is that is the wrong function to use, you must use the appropriate md5 function for your language.

Finally, to address the comment of Dennis Bottaro, this is because of the use of UTF-7 encoding in this example to hash the data. UTF-7 is actually poor choice for encoding data before hashing due to the representation of most non-alphanumeric characters as you have suggested above. This, compared to non-UTF-7 encoded data in the php md5() function will obviously yield different results due to the representation of the non-alphanumeric data.  To reiterate from before, the way to fix this is to make sure the encoding does not change, and also, make sure you are using the appropriate function within your languages function set.

-Ryan</description>
		<content:encoded><![CDATA[<p>I&#8217;m not a .NET programmer, but I may be able to address a few of the comments here. Starting with the article itself, I don&#8217;t believe that UTF-7 is the actual answer to your problems, but rather, a means of consistency for the data encoding before encryption. When computing a hash from a string, the data encoding is only important as to the extent of consistency in characters. What I mean by this is, if a string is being transmitted encoded as UTF-8 encrypted by md5 and compared against a ISO-8859-1 encoded string with the same characters it may or may not be equal due to the encoding, converting the strings in this example to UTF-7 is just a means of ensuring they are represented equivalently.</p>
<p>As for the comment by victorantos, the reason your output is not equivalent to php&#8217;s md5 without even knowing any .NET C# syntax is clear from the function call. HMAC-md5 (or any other HMAC-hash function) provides an additional functionality above the basic md5 hashing algorithm. The HMAC- algorithms are frequently used in API&#8217;s in which the transmitting parties share a secret key K and hash the data along with XORing K against  2 sets of data to explain simply. The basic explanation is that is the wrong function to use, you must use the appropriate md5 function for your language.</p>
<p>Finally, to address the comment of Dennis Bottaro, this is because of the use of UTF-7 encoding in this example to hash the data. UTF-7 is actually poor choice for encoding data before hashing due to the representation of most non-alphanumeric characters as you have suggested above. This, compared to non-UTF-7 encoded data in the php md5() function will obviously yield different results due to the representation of the non-alphanumeric data.  To reiterate from before, the way to fix this is to make sure the encoding does not change, and also, make sure you are using the appropriate function within your languages function set.</p>
<p>-Ryan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dennis Bottaro</title>
		<link>http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/comment-page-1/#comment-524</link>
		<dc:creator>Dennis Bottaro</dc:creator>
		<pubDate>Tue, 27 May 2008 17:46:09 +0000</pubDate>
		<guid isPermaLink="false">http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/#comment-524</guid>
		<description>This works perfectly when the incoming data is only alphanumeric.  I have run into trouble when the incoming has characters other than a-z,A-Z,1-0.  For example with this string &quot;t0ph@t&quot; php&#039;s MD5 comes up with &quot;aec0cbe6302f25d8cce350e324704a52&quot; while the version here comes up with &quot;0ad1d3db5ba9b96f248816794b579fb1&quot;

I have not tested changing the encoding, but wondered if anyone else ran across this same problem.  If I come up with a resolution, I will post it back here.</description>
		<content:encoded><![CDATA[<p>This works perfectly when the incoming data is only alphanumeric.  I have run into trouble when the incoming has characters other than a-z,A-Z,1-0.  For example with this string &#8220;t0ph@t&#8221; php&#8217;s MD5 comes up with &#8220;aec0cbe6302f25d8cce350e324704a52&#8243; while the version here comes up with &#8220;0ad1d3db5ba9b96f248816794b579fb1&#8243;</p>
<p>I have not tested changing the encoding, but wondered if anyone else ran across this same problem.  If I come up with a resolution, I will post it back here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lee Kelleher</title>
		<link>http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/comment-page-1/#comment-509</link>
		<dc:creator>Lee Kelleher</dc:creator>
		<pubDate>Thu, 22 May 2008 20:57:18 +0000</pubDate>
		<guid isPermaLink="false">http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/#comment-509</guid>
		<description>Hidden away under an un-intuitive namespace is...

System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(&quot;hashMe&quot;, &quot;MD5&quot;)

The outputted MD5 is in uppercase, so just add a .ToLower().</description>
		<content:encoded><![CDATA[<p>Hidden away under an un-intuitive namespace is&#8230;</p>
<p>System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(&#8220;hashMe&#8221;, &#8220;MD5&#8243;)</p>
<p>The outputted MD5 is in uppercase, so just add a .ToLower().</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morten K. Poulsen</title>
		<link>http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/comment-page-1/#comment-480</link>
		<dc:creator>Morten K. Poulsen</dc:creator>
		<pubDate>Thu, 24 Apr 2008 16:58:49 +0000</pubDate>
		<guid isPermaLink="false">http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/#comment-480</guid>
		<description>The MD5 algorithm digests blocks of 512 bits (64 bytes). It does not interpret the data in any way. So if you have a string of characters, you must represent them in the same way (US-ASCII, UTF-8, ISO-8859-15, ...) on each system, before hashing them. Otherwise you are hashing different byte sequences, and will - naturally - get different hash results.

Best regards,
Morten K. Poulsen</description>
		<content:encoded><![CDATA[<p>The MD5 algorithm digests blocks of 512 bits (64 bytes). It does not interpret the data in any way. So if you have a string of characters, you must represent them in the same way (US-ASCII, UTF-8, ISO-8859-15, &#8230;) on each system, before hashing them. Otherwise you are hashing different byte sequences, and will &#8211; naturally &#8211; get different hash results.</p>
<p>Best regards,<br />
Morten K. Poulsen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: victorantos</title>
		<link>http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/comment-page-1/#comment-478</link>
		<dc:creator>victorantos</dc:creator>
		<pubDate>Thu, 24 Apr 2008 14:24:42 +0000</pubDate>
		<guid isPermaLink="false">http://ok-cool.com/posts/read/125-php-md5-not-the-same-as-net-md5/#comment-478</guid>
		<description>That&#039;s what I&#039;m looking for, I was using 
&lt;i&gt;System.Security.Cryptography.HMACMD5 h = new System.Security.Cryptography.HMACMD5();            h.ComputeHash(data2);&lt;/i&gt;

&lt;b&gt; but it doesn&#039;t match with php generated hash&lt;/b&gt;</description>
		<content:encoded><![CDATA[<p>That&#8217;s what I&#8217;m looking for, I was using<br />
<i>System.Security.Cryptography.HMACMD5 h = new System.Security.Cryptography.HMACMD5();            h.ComputeHash(data2);</i></p>
<p><b> but it doesn&#8217;t match with php generated hash</b></p>
]]></content:encoded>
	</item>
</channel>
</rss>
