像 .net Core 中的表单身份验证一样加密密码
Encrypting Password Like Forms Authentication in .net Core
我有一个运行只读会员提供程序的旧应用程序。我的任务是创建一个管理页面来帮助此应用的 adding/changing/deleting 用户。会员提供者使用 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 核心中工作),散列密码是否能够 "validated" by FormsAuthentication
?
到目前为止,我的测试似乎没有效果。有任何想法吗?我做错了吗?
编辑:它不是 HMASHA1,它是 SHA1Cng - 我不能使用它,因为它在 .net 框架 System.Core 中 4.something...我可以用什么来做这个在 .net 核心中?
我想通了,这行得通:
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
仍然希望能够反向执行此操作并解密密码。
略有不同,数据库中的遗留散列密码
string incoming = inCrypt(inputPassword);
incoming=Regex.Replace(incoming, @"[^0-9a-zA-Z]", "");
public string inCrypt(string pwd)
{
var sha1 = SHA1.Create();
var step1 = System.Text.Encoding.UTF8.GetBytes(pwd);
var step2 = sha1.ComputeHash(step1);
var step3 = BitConverter.ToString(step2);
return step3.ToString();
}
有效,散列密码可以作为字符串进行比较。
我有一个运行只读会员提供程序的旧应用程序。我的任务是创建一个管理页面来帮助此应用的 adding/changing/deleting 用户。会员提供者使用 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 核心中工作),散列密码是否能够 "validated" by FormsAuthentication
?
到目前为止,我的测试似乎没有效果。有任何想法吗?我做错了吗?
编辑:它不是 HMASHA1,它是 SHA1Cng - 我不能使用它,因为它在 .net 框架 System.Core 中 4.something...我可以用什么来做这个在 .net 核心中?
我想通了,这行得通:
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
仍然希望能够反向执行此操作并解密密码。
略有不同,数据库中的遗留散列密码
string incoming = inCrypt(inputPassword);
incoming=Regex.Replace(incoming, @"[^0-9a-zA-Z]", "");
public string inCrypt(string pwd)
{
var sha1 = SHA1.Create();
var step1 = System.Text.Encoding.UTF8.GetBytes(pwd);
var step2 = sha1.ComputeHash(step1);
var step3 = BitConverter.ToString(step2);
return step3.ToString();
}
有效,散列密码可以作为字符串进行比较。