代码之家  ›  专栏  ›  技术社区  ›  Barry Franklin

在.NET核心中加密类似表单身份验证的密码

  •  0
  • Barry Franklin  · 技术社区  · 7 年前

    我有一个运行只读成员资格提供程序的旧应用程序。我的任务是创建一个管理页面,以帮助添加/更改/删除此应用程序中的用户。成员资格提供程序使用 FormsAuthentication ,因为我的管理应用程序在.NET核心中,所以无法使用。我正在尝试反向工程他们使用的加密方式 表格认证 到目前为止我有:

    它们使用:

    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步是这样的“ad626b9d42073b29ecfc664ccb7ab01f3af726”,它看起来像旧应用程序的XML用户文件中的密码。

    我只是好奇,如果我使用这种哈希方法(在.NET核心中工作),哈希密码是否能够通过 表格认证 ?

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

    编辑:它不是hmasha1,它是sha1cng,我不能使用它,因为它在.NET框架4的system.core中。在.NET核心中,我可以使用什么来执行此操作?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Barry Franklin    7 年前

    我明白了,这是可行的:

    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

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

    推荐文章