我在下面有一個散列函式,128 位元組散列是密碼過度殺傷還是殺傷力不足?
public string HashPassword(string password)
{
Rfc2898DeriveBytes rfc = new(
password,
_salt,
_iterations,
_hashAlgorithmName
);
// is 128 bytes a good number?
var hashedPasswordBytes = rfc.GetBytes(128);
return Convert.ToBase64String(hashedPasswordBytes);
}
uj5u.com熱心網友回復:
這與您使用的輸出長度有關_hashAlgorithmName。例如,如果您使用 HMAC-SHA512,則輸出長度為 512 位(64 位元組),并且獲得比 64 位元組更多的位元組有點過大。對于今天的標準,即使是 256 位的熵也足夠了。
實際上,這就是為什么 ASP.NET Core Identity 包在使用 HMAC-SHA512 使用 Rfc2898DeriveBytes 對密碼進行哈希處理時僅使用 32 個位元組(256 位)的原因。
供參考: https ://github.com/dotnet/aspnetcore/blob/main/src/Identity/Extensions.Core/src/PasswordHasher.cs
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/455175.html
下一篇:重繪令牌對服務器性能的影響
