Hello everyone. In a WinForm application using C#.NET 2.0 (on Vista), I am using SHA1 hash to create a hash from a string and store the hash in a text file (with UTF-8 encoding). I want to use the hash stored in text file to in a condition. When I run the project in Vista it works properly (i.e. the condition results in true), but when I run in XP the project does not run.
Is the way hash created in Vista different from XP?
Code extract
byte[] HashValue;
byte[] MessageBytes = Encoding.UTF8.GetBytes(strPlain);
SHA1Managed SHhash = new SHA1Managed();
StringBuilder strHex = new StringBuilder("");
HashValue = SHhash.ComputeHash(MessageBytes);
foreach (byte b in HashValue)
{
strHex.AppendFormat("{0:x2}", b);
}
// storing strHex in a text file with UTF-8 encoding
Test condition
string newHash = Program.GetHash("This will be hashed.");
// GetHash() does has the same code as above, but instead of storing hash in file in return
// hash.
bool validHash = newHash.Equals(oldHash);
// old has is the one stored in file
if (validHash)
{
// some code
}
[Edit]
The main problem is the same code works fine in Vista, but breaks down in XP. If there is some logical problem it should not work in any OS.
Thanks.