LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-02-2012, 09:19 AM   #1
laks
Member
 
Registered: Feb 2012
Posts: 34

Rep: Reputation: Disabled
Is the result of MD5 calculation consistant?


Hello All,

I am trying to generate MD5Hash of a large number of files(.7z files) from java. I am using MessageDigest to do the same. However, the problem I am facing is that the output MD5Hashes are not consistant;changing everytime it is running(for same files). This is being run on Linux suse 10. Could anyone tell me if MD5calculation is dependent on platform and can change with multiple iterations?

Regards,
Lakshmi
 
Old 05-02-2012, 09:21 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938
MD5 is a digital-signature algorithm. If the signatures are changing, the files are changing ... or, just as likely, there's a bug in your code.
 
1 members found this post helpful.
Old 05-02-2012, 11:00 PM   #3
laks
Member
 
Registered: Feb 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
Files are changing but file size and contents remain same. This is what my program does .

1. Reads a set of .gz files.
2. Archives them to a set of 7z files.
3. Calculates MD5Hash of 7z files.

At the third step, I am getting different results for same set of .gz files.

I have executed my program for many other data sets, but it works for all of them and fails only for this particular set. I am almost stuck with no way out for further debugging.
 
Old 05-03-2012, 02:49 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
This is natural. Using the MD5 algorithm on files something.gz and something.7z (or .Z, .xz, .bz2 etc) will give different results, even if they are both the compressed versions of the same something file.
 
Old 05-03-2012, 03:46 AM   #5
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
I noticed recently that files compressed using xz (another lz/7z format) have an inconsistent size by a few bytes when repeatedly built. This may be the OP's problem.
 
1 members found this post helpful.
Old 05-03-2012, 08:52 AM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938
File formats can also have some "unpredictable" bytes, and even one bit will completely change a signature.
 
Old 05-03-2012, 10:30 PM   #7
laks
Member
 
Registered: Feb 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
Hello,

Finally I found out the problem. Though the gz files remain the same, some of the gz files were having a different timestamp(Replaced or recreated by an external process) every time the process was ran. Hence MD5Hash was changing due to this change in timestamp of files.
Thanks to everyone for their valuable replies.

Marking this thread resolved.

Regards,
Lakshmi
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
56k string to make speed consistant ? blackcat09 Linux - Networking 1 11-21-2009 07:46 PM
consistant boot error after fresh install Dknife9 Slackware 2 04-14-2007 09:22 PM
md5() function in php gives different result than md5sum on linux baikonur Programming 2 08-24-2006 04:41 AM
shell - acting on result of calculation corck Programming 3 07-05-2005 09:16 AM
installation not consistant Red Squirrel Linux - Newbie 3 12-15-2003 03:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration