【问题标题】:Encrypting Password Like Forms Authentication in .net Core在 .net Core 中像表单身份验证一样加密密码
【发布时间】:2018-12-28 18:31:26
【问题描述】:

我有一个运行只读会员提供程序的旧应用程序。我的任务是创建一个管理页面来帮助从这个应用程序添加/更改/删除用户。会员提供者使用FormsAuthentication,我无法使用它,因为我的管理应用程序位于 .net Core 中。我正在尝试对他们使用FormsAuthentication 加密的方式进行逆向工程,到目前为止我有这个:

他们使用:

FormsAuthentication.HashPasswordForStoringInConfigFile(password, "sha1").ToLower();

我已经对其进行了逆向工程:

(传入字符串pwd)

HashAlgorithm hashAlgorithm = new HMASHA1();
var step1 = Encoding.UTF8.GetBytes(pwd);
var step2 = hashAlgorithm.ComputeHash(step1);
var step3 = BinaryToHex(step2);

第 3 步的结果类似于“AD626B9D42073B299ECFC664CCB7A8B01F3AF726”,看起来就像旧应用程序的 XML 用户文件中的密码一样。

我很好奇如果我使用这种散列方法(适用于 .net 核心),散列后的密码是否能够被FormsAuthentication“验证”?

到目前为止,我的测试似乎没有奏效。有任何想法吗?我做错了吗?

编辑:它不是 HMASHA1,它是 SHA1Cng - 我不能使用它,因为它在 .net 框架的 System.Core 中 4.something...我可以在 .net 核心中使用什么来执行此操作?

【问题讨论】:

  • 试试var newPassword=_userManager.PasswordHasher.HashPassword(user,newpass);。如果默认哈希不适合你,你也可以参考source code here

标签: asp.net-core hash passwords forms-authentication


【解决方案1】:

我想通了,这行得通:

using System.Security.Cryptography;

var sha1 = SHA1.Create();
var step1 = Encoding.UTF8.GetBytes(pwd);
var step2 = sha1.ComputeHash(step1);
var step3 = BinaryToHex(step2);   

BinaryToHex 及其相关函数是从System.Web.Security.Cryptography.CryptoUtil 复制而来的

仍然希望能够反向执行此操作并解密密码。

【讨论】:

    猜你喜欢
    • 2014-05-30
    • 2014-07-31
    • 1970-01-01
    • 2017-10-30
    • 1970-01-01
    • 2011-03-01
    • 1970-01-01
    • 2011-01-03
    • 2011-05-08
    相关资源
    最近更新 更多