我一辈子都无法在没有任何更改的ASP.NET MVC模板应用程序中识别Cryptography.KeyDerivation。我环顾四周,看到一些
使用Microsoft.AspNetCore.Cryptography.KeyDerivation;
-或-
使用Microsoft.AspNet.Cryptography.KeyDerivation;
-但即使是
使用System.Security.Cryptography.KeyDerivation;未在中列出
https://msdn.microsoft.com/en-us/library/system.security.cryptography%28v=vs.110%29.aspx
我想使用我在网上找到的代码来覆盖默认版本的PasswordHasher,该版本使用HMACSHA1并使用HMACSHA 526,而不是:
string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
password: password,
salt: salt,
prf: KeyDerivationPrf.HMACSHA1,
iterationCount: 10000,
numBytesRequested: 256 / 8));
并使用HMACSHA512的prf来覆盖PasswordHasher的基类,该基类只有一个具有要传入的密码的构造函数
最后一个问题是,一旦完成了这项工作,我就不能把代码放在ApplicationUserManager中吗?
public ApplicationUserManager(IUserStore<ApplicationUser> store) : base(store)
{
//code here
}
System.Security.Cryptography.Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(input, salt, 10000);
string hashed = Convert.ToBase64String(rfc2898DeriveBytes.GetBytes(256 / 8));
对我来说工作酒。如果仅使用KeyDerivationPrf.HMACSHA1。