I’m trying to work out whether values that have been hashed (using the code below) will be different if the machine key value is different. Also, I’d like to know if implementations in other languages (i.e. Java) would produce different results.
string hashedPassword = Convert.ToBase64String(
new System.Security.Cryptography.SHA1CryptoServiceProvider().ComputeHash(
System.Text.Encoding.Default.GetBytes(password)));
(I’ve tried to find an answer on Google but I cannot find anything definitive.)
SHA1CryptoServiceProvider.ComputeHash()will always return the same result for the same input (regardless of which machine it is run on). Any other correctly implemented SHA1-algorithm will also give the same result.But note that you use
System.Text.Encoding.Default.GetBytes(password)to calculate the input. This will not be independent of the machine! You should strongly consider usingEncoding.UTF8instead.