C# 为内容安全策略提供了与脚本哈希器不同的内联字符串哈希值

问题描述 投票:0回答:1

我有一个使用 stringbuilder 构建的 C# 字符串。有 2 行有输出:

Line1
Line2

我用这段代码进行哈希:

public static string GetSha256Hash(string input)
{
    using (SHA256 sha256Hash = SHA256.Create())
    {
        byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
        return Convert.ToBase64String(bytes);
    }
}

CSPLite 创建正确的以下哈希:

enter image description here

然而,.net(下面是 C# 或 VB.Net)会创建不同的哈希值,因为换行符的处理方式可能不同 vb.net equivalent of hashing code

如果我复制并粘贴同一字符串的output,那么我会得到正确的哈希值

enter image description here

如何调整 C# 字符串以创建与 CSP 创建的哈希值相同的哈希值?

hash content-security-policy sha
1个回答
0
投票

空白可能存在差异。尾随换行符或一个将换行符视为 另一个作为 和 .

© www.soinside.com 2019 - 2024. All rights reserved.