asp.net-core - 在 .net Core 中像表单例份验证一样加密密码

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

我有一个运行只读成员(member)资格提供商的旧应用程序。我的任务是创建一个管理页面,以帮助在此应用程序中添加/更改/删除用户。成员(member)资格提供程序使用 FormsAuthentication,我无法使用它,因为我的管理应用程序位于 .net Core 中。我正在尝试使用 FormsAuthentication 对它们的加密方式进行逆向工程,到目前为止我已经做到了:

他们使用:

FormsAuthentication.HashPasswordForStoringInConfigFile(密码, "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 core中工作),散列密码是否能够被FormsAuthentication“验证”?

到目前为止我的测试似乎不起作用。有任何想法吗?我做错了吗?

编辑:它不是 HMASHA1,而是 SHA1Cng - 我无法使用它,因为它位于 .net Framework 4.something 中的 System.Core 中...我可以使用什么在 .net core 中执行此操作?

最佳答案

我明白了,这有效:

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

复制的

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

关于asp.net-core - 在 .net Core 中像表单例份验证一样加密密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53962874/

相关文章:

security - 你如何强制执行强密码?

c# - 如何在 .Net Core 3、Visual Studio 2019 和 docker 中使用 "dotnet watch run"

c# - 使用 Controller 方法注入(inject) Dotnet 核心方法

perl hash ref 运算符工作异常

ruby-on-rails - 在 ruby​​ 中重新排序哈希。让一把 key 永不过时

javascript - 在 AngularJS 中,如何在输入有效数据后在输入字段前显示绿色勾号?

c# - 带有外键列表的附加属性

c# - 无法转换类型为 'Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope' 的对象

security - 散列 SSN 和其他有限域信息

c - 从编码的哈希值中导出 Argon2 类型是否安全?