Bug 12265 - MD5 Hash generation different on 6.2.1 and 6.2.5
Summary: MD5 Hash generation different on 6.2.1 and 6.2.5
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.2.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2013-05-16 07:46 UTC by wilhelm
Modified: 2013-05-16 11:27 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Test class (889 bytes, application/octet-stream)
2013-05-16 07:46 UTC, wilhelm
Simple Test case (1.68 MB, application/zip)
2013-05-16 08:25 UTC, wilhelm

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description wilhelm 2013-05-16 07:46:35 UTC
Created attachment 3974 [details]
Test class


generation of MD5 Hash of a json string seems to be different between 6.2.1 and 6.2.5

Please see attached file for a test class that retrieves the string and calculates the hash using ObjectExtensions.cs from   alexmg.com/post/2009/04/16/Compute-any-hash-for-any-object-in-C.aspx

The string is retrieved from the server looks like this:

{"items":[{"greeting":"Hello world"}]}

The hash produced on 6.2.1 looks like this: RqyBkiJ4p2YxG7CukJlYxg==
The hash produced on 6.2.5 looks like this: jCq8KLrSEBMrpjt11ptf5g==
Comment 1 Sebastien Pouliot 2013-05-16 08:00:47 UTC
As I said on the forums I strongly suspect a different string is being generated and I want to be sure I'm testing the same code as you are (including the same version of ResetSharp and the code from your link). 

Please provide a self contained test case, including all dependencies.
Comment 2 wilhelm 2013-05-16 08:25:37 UTC
Created attachment 3975 [details]
Simple Test case

This archive contains a simple test application, including RestSharp and ObjectExtensions.cs.
Comment 3 Sebastien Pouliot 2013-05-16 11:27:17 UTC
Thanks! This is the byte stream and the hash I get with 6.2.6 (not yet released, but identical to your result with 6.2.5).

2013-05-16 11:13:27.097 JsonHashTest[66926:c07] EF-BB-BF-3C-73-74-72-69-6E-67-20-78-6D-6C-6E-73-3D-22-68-74-74-70-3A-2F-2F-73-63-68-65-6D-61-73-2E-6D-69-63-72-6F-73-6F-66-74-2E-63-6F-6D-2F-32-30-30-33-2F-31-30-2F-53-65-72-69-61-6C-69-7A-61-74-69-6F-6E-2F-22-3E-7B-22-69-74-65-6D-73-22-3A-5B-7B-22-67-72-65-65-74-69-6E-67-22-3A-22-48-65-6C-6C-6F-20-77-6F-72-6C-64-22-7D-5D-7D-3C-2F-73-74-72-69-6E-67-3E

2013-05-16 11:13:27.099 JsonHashTest[66926:c07] jCq8KLrSEBMrpjt11ptf5g==

Note the three first bytes, EF BB BF - those are encoding bytes for UTF8, ref: http://en.wikipedia.org/wiki/Byte_order_mark

If I remove those 3 first bytes the MD5 digest becomes:

2013-05-16 11:19:04.981 JsonHashTest[66986:c07] RqyBkiJ4p2YxG7CukJlYxg==

which is exactly what you had using 6.2.1.

So something, somewhere, changed the encoding of your JSON string (it might have been a bug fix). However the hash algorithms (MD5 or any other) are still working fine.

Like I said on the forums string encoding are one of the major issues wrt digesting. The digest process is byte, not string, oriented. This means you must take care, e.g. sanitize, any string prior to digesting them (or your values might differs on different platforms, cultures...).