【问题标题】:System.Security.Cryptography.KeyDerivation not being recognized in VS Community 2015 ver. 14.0.2System.Security.Cryptography.KeyDerivation 在 VS Community 2015 版本中未被识别。 14.0.2
【发布时间】:2016-07-20 16:13:00
【问题描述】:

在我的一生中,我无法在没有任何更改的模板 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

我想使用我在网上找到的代码来覆盖使用 HMACSHA1 并改用 HMACSHA526 的 PasswordHasher 的默认版本:

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
}

【问题讨论】:

    标签: c# asp.net-mvc hashcode visual-studio-2015


    【解决方案1】:
    System.Security.Cryptography.Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(input, salt, 10000);
    string hashed = Convert.ToBase64String(rfc2898DeriveBytes.GetBytes(256 / 8));
    

    对我来说工作酒。如果只使用 KeyDerivationPrf.HMACSHA1。

    【讨论】:

    • 即使这行得通,我还没有测试过,这不是问题所要问的,因为我说我想使用 HMACSHA526。
    猜你喜欢
    • 1970-01-01
    • 2015-10-10
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    • 2021-11-22
    • 2016-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多