SHA256CryptoServiceProvider不符合FIPS标准?

tof*_*tim 5 c# encryption

我正在寻找符合FIPS标准的C#中的SHA256实现.事实证明SHA1CryptoServiceProvider工作.但是为什么SHA256CryptoServiceProvider会绊倒

{"This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms."}
Run Code Online (Sandbox Code Playgroud)

错误?似乎应该只是工作.

var sha = System.Security.Cryptography.SHA256CryptoServiceProvider.Create();   // not FIPS
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我使用的是.NET 4.5,但同样的事情发生在3.5和4.0中.我认为SHA256CryptoServiceProvider是符合FIPS标准的SHA256Managed替代品.SHA256Cng抛出相同的错误.

更新.我想我需要制作一个"新的SHA256CryptoServiceProvider"而不是使用Create()

And*_*son 6

正如更新中建议的原始海报,解决方案是实际创建 SHA256CryptoServiceProvider(或 512)的新实例。调用 Create 将不起作用:

var csp = new SHA512CryptoServiceProvider();
byte[] hashedBytes = csp.ComputeHash(......);
String hashedText = Convert.ToBase64String(hashedBytes); 
Run Code Online (Sandbox Code Playgroud)