I’m re-writing a Rails web app in C#. I’m really stuck with Ruby’s hash function:
# Generates a 128 character hash
def Password.hash(password,salt)
Digest::SHA512.hexdigest("#{password}:#{salt}")
end
The following C# function gives a different result:
private static string Hash(string password, string salt)
{
return BitConverter.ToString(new SHA512CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(password + ":" + salt))).Replace("-", "").ToLower();
}
What am I doing wrong?
Thank you
Never mind. The results actually ARE the same. So if you ever need to convert Ruby’s hashing to C#,
does the same as
C# is a lot more verbose, but the main thing is that it works! 🙂