Note that there are some explanatory texts on larger screens.

plurals
  1. POFunction returns different MD5 hash each time
    text
    copied!<p>I have written a function that takes the URL of a file as a parameter and returns the MD5 hash of that file.</p> <p>The hash generated by this function (in the development environment) matches the hash generated by a third-party tool for the same file.</p> <p>But when this was deployed in my client's QA environment, this function returns different values each time the function is called.</p> <p>I did some Google-ing and found that the issue might be because the dev. server is 64bit and the QA server was 32bit. Since I do not have access to my client's servers, I deployed it in another 32bit server and found that the hashes match even in a 32bit server(function works as expected?).</p> <p>I also had a look at <a href="https://stackoverflow.com/questions/1347866/md5-file-hash-for-the-same-unchanged-file-is-different-each-time-c-sharp">this question</a>.</p> <p>here is the function I wrote:</p> <pre><code>public static String GetMD5HashFromFile(String url) { String response = String.Empty; HttpWebRequest aRequest = (HttpWebRequest)WebRequest.Create(url); using (HttpWebResponse aResponse = (HttpWebResponse)aRequest.GetResponse()) { MD5 md5 = new MD5CryptoServiceProvider(); byte[] retVal = md5.ComputeHash(aResponse.GetResponseStream()); response = "MD5:" + BitConverter.ToString(retVal).Replace("-", string.Empty); } return response; } </code></pre> <p>My questions are; what could be the reason for this function to return various values? Is the issue in my function?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload