【问题标题】:Why System.Security.Cryptography SHA256 hash cannot be decrypted by online hash tool?为什么 System.Security.Cryptography SHA256 哈希不能被在线哈希工具解密?
【发布时间】:2019-12-08 21:18:45
【问题描述】:

我尝试在此website 上生成哈希并在此hash decryptor website 上对其进行解密,它确实可以解密但不能解密从 System.Security.Cryptography 生成的哈希。为什么?这是否意味着 Cryptography 命名空间使用不同的算法?

使用 .Net Core 2.2 的代码参考

    static byte[] calculateHash(string source)
    {
        ASCIIEncoding converter = new ASCIIEncoding();
        byte[] sourceBytes = converter.GetBytes(source);

        HashAlgorithm hasher = SHA256.Create();
        byte[] hash = hasher.ComputeHash(sourceBytes);

        return hash;
    }

    static void showHash(string source)
    {
        Console.WriteLine("Has for {0} is:", source);
        byte[] hash = calculateHash(source);
        foreach(byte b in hash)
        {
            Console.Write("{0:X}",b);

        }
        Console.WriteLine();
    }

【问题讨论】:

  • 如果你能分享minimal reproducible example,那就太棒了。确保在问题中的代码中包含source
  • 尝试 Console.Write(“{0:X2}”),对于小于 16 的任何字节,您都会丢失前导零。

标签: c# hash cryptography


【解决方案1】:

SHA256 是 散列 函数,而不是加密函数。由于SHA256不是加密函数,所以无法解密。

你的意思可能是颠倒过来。在这种情况下,SHA256 无法反转,因为它是单向函数。

您引用的站点只是一个包含已知哈希值和输入字符串的数据库。这种工具的明显限制是它不能用于尚未添加的哈希。

【讨论】:

  • 感谢您的关注您引用的站点只是一个已知哈希值和输入字符串的数据库。因此这意味着该站点不知道 Cryptography 命名空间生成的哈希?
  • @RonaldAbellano 是的,为您的特定输入字符串生成的哈希是未知的。本质上,可能的输入字符串和哈希值组合的数量是无限的。
猜你喜欢
  • 1970-01-01
  • 2012-02-09
  • 1970-01-01
  • 2021-02-25
  • 2013-09-11
  • 1970-01-01
  • 2016-07-27
  • 2021-04-25
  • 1970-01-01
相关资源
最近更新 更多