作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 HMACSHA256 和以下代码创建键控 SHA256 哈希:
HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secretKey);
byte[] hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(data));
string hashResult = string.Empty;
for (int i = 0; i < hash.Length; i++)
{
hashResult += hash[i].ToString("x2"); // hex format
}
这工作得很好,但是,它在启用 FIPS 的环境中失败,因为 HMACSHA256 使用底层 SHA256Managed 实现,它本身不符合 FIPS。
通过 MSDN 文档搜索,我发现 KeyedHashAlgorithm 的唯一 SHA256 实现是 HMACSHA256。
我需要使用键控 SHA256 哈希对 Web 服务请求进行签名(因此我无法更改哈希类型),并且我必须能够在启用 FIPS 的环境中运行。
Google 显示 SHA256CryptoServiceProvider 和 SHA256Cng 都是创建 SHA256 哈希的 FIPS 兼容方法,但似乎都不支持创建键控哈希。
最佳答案
我知道这已经过时了,但看起来 Microsoft 解决了这个问题。我在 Windows 8 上运行 .NET 4.5.1。我不知道这是修复的 BCL 版本还是操作系统。
this.m_hash1 = HMAC.GetHashAlgorithmWithFipsFallback((Func<HashAlgorithm>) (() => (HashAlgorithm) new SHA256Managed()), (Func<HashAlgorithm>) (() => HashAlgorithm.Create("System.Security.Cryptography.SHA256CryptoServiceProvider")));
关于c# - 是否有符合 .NET FIPS 的键控 SHA256 哈希算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17862491/
我是一名优秀的程序员,十分优秀!