我有一个运行只读成员(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/