本文介绍了SHA256CryptoServiceProvider不符合FIPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要寻找一个在C#中SHA256的实现,是符合FIPS。事实证明,SHA1CryptoServiceProvider工作。但是为什么SHA256CryptoServiceProvider跳闸
error? Seems like it should just work.
var sha = System.Security.Cryptography.SHA256CryptoServiceProvider.Create(); // not FIPS
In this case I am using .NET 4.5, but the same thing happens in 3.5 and 4.0. I thought SHA256CryptoServiceProvider was the FIPS-compliant alternative to SHA256Managed. SHA256Cng throws the same error.
Update. I think I needed to make a "new SHA256CryptoServiceProvider" instead of using Create()
解决方案
As the original poster suggested in the update, the solution is to actually create a new instance of the SHA256CryptoServiceProvider (or 512). Calling Create will not work:
var csp = new SHA512CryptoServiceProvider();
byte[] hashedBytes = csp.ComputeHash(......);
String hashedText = Convert.ToBase64String(hashedBytes);
这篇关于SHA256CryptoServiceProvider不符合FIPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!