2

I have an MD5 hash method like so:

MD5 md5 = System.Security.Cryptography.MD5.Create();
        StringBuilder sb = new StringBuilder();
        lock (md5)
        {
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
            byte[] hash = md5.ComputeHash(inputBytes);

            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2").ToString(CultureInfo.InvariantCulture));
            }
        }
        return sb.ToString();

On several local dev machines using the same input, this returns the same hash. On staging and live servers too, it is returnging the expected value.

However, on a few local development machines the values differ. And I cannot figure out why?

I added the lock and the CultureInfo in response to some other answers on here.. but alas. Nothing.

Any and all help is greatly appreciated in this matter!

UPDATE:

I have gotten to the point where I compared the inputBytes array on a 'good' vs. a 'bad' machine and the arrays are identical.

So what, if anything, could the ComputeHash method be doing differently between machines? I feel like that isn't the underlying issue.. but at this point that is where the hash comes back different. I am at a loss.

4

1 回答 1

1

As said by @bartdude the input was different on either machine due to a datetime variable that was pulling from different system time formats.

Hopefully this helps someone in the future.

于 2013-05-16T15:43:29.167 回答