如果我使用SHA256使用下面的方法,我得到這個作爲我的輸出散列字符串「密碼」,在C#:SHA256哈希值不與哈希同意網站
e201065d0554652615c320c00a1d5bc8edca469d72c2790e24152d0c1e2b6189
但this website(SHA-256 produces a 256-bit (32-byte) hash value)告訴我已經是:
5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8
我顯然有一個數據格式問題或類似的東西。任何想法爲什麼這個C#SHA256Managed方法返回不同的東西?我發送方法「密碼」作爲輸入參數。
private static string CalculateSHA256Hash(string text)
{
UnicodeEncoding UE = new UnicodeEncoding();
byte[] hashValue;
byte[] message = UE.GetBytes(text);
SHA256Managed hashString = new SHA256Managed();
string hex = "";
hashValue = hashString.ComputeHash(message);
foreach (byte x in hashValue)
{
hex += String.Format("{0:x2}", x);
}
return hex;
}
請不要使用SHA256哈希來存儲密碼(假設您是從頭開始設計的)。請閱讀關於存儲密碼的現代方法,您應該使用如下所示:https://msdn.microsoft.com/en-us/library/system.security.cryptography.rfc2898derivebytes(v=vs.110).aspx或一些其他的多迭代方法。 – willaien
感謝您的鏈接。我們使用SHA256,後端對用戶來說是獨一無二的,而且我們不是雙重哈希。看起來我們可以改進的是使用PBKDF2而不是SHA256。 – LampShade