473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Different Hash

91
I'm a bit confused on this one. I created a DLL in 3.5 .NET and on my Vista Laptop the md5 hash is different from the md5 hash on my XP Desktop. It is the EXACT same file as I downloaded it from the same location however they both run fine just the hash is different? Can anyone explain this?

I have my update program checking files hash's against an XML file so see if new updates are available and this is causing a problem as everytime the update is run it says there are new updates because of the hash mismatch.

This is only happening to the DLL. The .exe's that were created on my Vista Laptop (Same as the .dll) have the same has on both the XP and Vista pc. I Can't explain it...
Sep 12 '08 #1
5 1968
Teme64
10
Do you use similar code to calculate MD5 as below:

Expand|Select|Wrap|Line Numbers
  1. Dim ResultMD5() As Byte
  2. Dim ProvMD5 As MD5
  3.  
  4. ProvMD5 = MD5CryptoServiceProvider.Create()
  5. ProvMD5.Initialize()
  6. ResultMD5 = ProvMD5.ComputeHash(BytesIn)
  7.  
Do you convert resulting MD5 to a 32-character long string? If you do, do you have leading zeros, so that the string is 32-character long?
One other thing could be "off by one error". I used following (simplified) code to calculate MD5:

Expand|Select|Wrap|Line Numbers
  1. BufSize = CInt(StreamIn.Length)
  2. ReDim MemBuf(BufSize - 1)
  3. StreamIn.Read(MemBuf, 0, BufSize)
  4. ' Calculate MD5
and in the verification code I had

Expand|Select|Wrap|Line Numbers
  1. BufSize = CInt(StreamIn.Length)
  2. ReDim MemBuf(BufSize)
  3. StreamIn.Read(MemBuf, 0, BufSize)
  4. ' Calculate MD5
so I allocated 1-byte larger buffer which caused MD5 to differ.

Does your code produce correct MD5-values on the same OS, like in XP?

Basically, there shouldn't be any difference between XP and Vista that causes different MD5 values.
Sep 15 '08 #2
arggg
91
I'm using C# MD5CryptoServices
Sep 15 '08 #3
arggg
91
Here is my code

Expand|Select|Wrap|Line Numbers
  1.         /*
  2.          * MD5 Hash
  3.          */
  4.         public static string GetMD5Hash(string pathName)
  5.         {
  6.             string strResult = "";
  7.             string strHashData = "";
  8.  
  9.             byte[] arrbytHashValue;
  10.             System.IO.FileStream oFileStream = null;
  11.  
  12.             System.Security.Cryptography.MD5CryptoServiceProvider oMD5Hasher =
  13.                        new System.Security.Cryptography.MD5CryptoServiceProvider();
  14.  
  15.             try
  16.             {
  17.                 oFileStream = GetFileStream(pathName);
  18.                 arrbytHashValue = oMD5Hasher.ComputeHash(oFileStream);
  19.                 oFileStream.Close();
  20.  
  21.                 strHashData = System.BitConverter.ToString(arrbytHashValue);
  22.                 strHashData = strHashData.Replace("-", "");
  23.                 strResult = strHashData;
  24.             }
  25.             catch (System.Exception ex)
  26.             {
  27.                 /*System.Windows.Forms.MessageBox.Show(ex.Message, "Error!",
  28.                            System.Windows.Forms.MessageBoxButtons.OK,
  29.                            System.Windows.Forms.MessageBoxIcon.Error,
  30.                            System.Windows.Forms.MessageBoxDefaultButton.Button1);*/
  31.                 return "0";
  32.             }
  33.  
  34.             return (strResult);
  35.         }
  36.  
the md5 for my .dll file differs on xp and vista however the 2 .exe's do not differ.

EDIT: i dont know why provider is split into provi der but it is together in my code.
Sep 18 '08 #4
arggg
91
It doesnt seem to be an issue with the code that gets the MD5 as I have another md5 program which runs as a shell on both my xp and vista machines and they both display different hashes for the same file which is the dll as well.

Here is the code for PB_Sock.dll

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6. using System.IO;
  7. using System.Reflection;
  8. using System.Runtime.InteropServices;
  9. using System.Windows.Forms;
  10.  
  11.  
  12. namespace PB_Sock
  13. {
  14.     public class AuthSock
  15.     {
  16.         [DllImport("user32.dll", EntryPoint="MessageBox")]
  17.         public static extern int ShowMessage(int hWnd, string text, string caption, uint type);
  18.  
  19.         string loginUrl = "http://website.com/update.php?action=auth&login={0}&password={1}";
  20.  
  21.         public bool getAuthenticated(String user, String pass)
  22.         {
  23.             // *** Establish the request
  24.  
  25.             String loginUrlSend = String.Format(loginUrl, user, pass);
  26.             HttpWebRequest Http =(HttpWebRequest) WebRequest.Create(loginUrlSend);
  27.  
  28.             // *** Set properties
  29.             Http.Timeout = 7000;    // 7 secs
  30.             Http.UserAgent = "PATc v" + 
  31.                 Assembly.GetExecutingAssembly().GetName().Version.ToString() + " Client";
  32.  
  33.             // *** Retrieve request info headers
  34.             try
  35.             {
  36.                 HttpWebResponse WebResponse = (HttpWebResponse)Http.GetResponse();
  37.                 Encoding enc = Encoding.GetEncoding(1252);  // Windows default Code Page
  38.  
  39.                 StreamReader ResponseStream = new StreamReader(WebResponse.GetResponseStream(), enc);
  40.  
  41.                 string Html = ResponseStream.ReadToEnd();
  42.                 string status = WebResponse.StatusCode.ToString();
  43.  
  44.                 WebResponse.Close();
  45.                 ResponseStream.Close();
  46.                 if (status.Contains("OK") == true)
  47.                 {
  48.                     if (Html.CompareTo("OK") == 0)
  49.                     {
  50.                         return true;
  51.                     }
  52.                     else
  53.                     {
  54.                         return false;
  55.                     }
  56.                 }
  57.                 else
  58.                 {
  59.                     return false;
  60.                 }
  61.             }
  62.             catch
  63.             {
  64.                 MessageBox.Show("Could not establish a connection with the authentication server.",
  65.                     "Authentication Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
  66.                     return false;
  67.             }
  68.         }
  69.     }
  70. }
  71.  
Sep 18 '08 #5
arggg
91
Any ideas on what is going on?
Sep 19 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Alex Vinokur | last post by:
Here is some function that detects if a vector contains only different elements bool vector_contains_only_different_elements (const vector<int>& v) { for (int i = 0; i < v.size(); i++) { if...
6
by: Pedro Alves | last post by:
Hi I'm having serious problems with a mission critical app that runs on postgres (and has been running for the past 3 years). It's rather large, and lately things are not going well. The...
14
by: Clint Olsen | last post by:
I was wondering if it's considered undefined behavior to use a member of a union when it wasn't initialized with that member. Example: typedef unsigned long hval_t; hval_t hval_init(void) {...
0
by: no game | last post by:
I have a problem with signature using RSACryptoServiceProvider I use signature=privKey.SignData(byteData, new MD5CryptoServiceProvide), and get a byte array of signature. The other...
0
by: fake ID | last post by:
Since you can't search for these symbols used in asp.net "<%#" or '<%=' I thought i'd post this to make things a little easier to find. Potential search word combinations: -lessthan Percentage...
10
by: Qiangning Hong | last post by:
I'm writing a spider. I have millions of urls in a table (mysql) to check if a url has already been fetched. To check fast, I am considering to add a "hash" column in the table, make it a unique...
6
by: Hongbo | last post by:
Hi, I use System.Security.Cryptography.HashAlgorithm.ComputeHash() method with SHA512 to encrypt password. I recently upgrade my website from .Net 1.1 to .Net 2.0. The passwords stop working....
4
by: Kerem Gümrükcü | last post by:
Hi, this is not a pure MFC/VC++ question but my apologizes at first. Well, i have a application that calculates the hash for a file. You can request a CALG_SHA1 or a CALG_MD5 for the File. The...
10
by: Smurff | last post by:
Hi All, Should an md5 hash of the same string output the same hash on Windows and Unix? I downloaded md5.c from http://www.advogato.org/article/830.html and compiled it on windows via cygwin...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.