Skip to content

Instantly share code, notes, and snippets.

@gregmac
Last active October 2, 2019 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregmac/43c346ab7d1fe00131794e5aa4162daf to your computer and use it in GitHub Desktop.
Save gregmac/43c346ab7d1fe00131794e5aa4162daf to your computer and use it in GitHub Desktop.
.NET FIPS test

FIPS testing

FIPS mode on

SHA256

SHA256.Create()

9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08

new SHA256Cng()

9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08

new SHA256CryptoServiceProvider()

9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08

new SHA256Managed()

This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.

MD5

MD5.Create()

This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.

new MD5Cng()

This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.

new MD5CryptoServiceProvider()

This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.

SHA1

SHA1.Create()

A94A8FE5CCB19BA61C4C0873D391E987982FBBD3

new SHA1Cng()

A94A8FE5CCB19BA61C4C0873D391E987982FBBD3

new SHA1CryptoServiceProvider()

A94A8FE5CCB19BA61C4C0873D391E987982FBBD3

new SHA1Managed()

This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.

void Main()
{
var value = "test";
Hash(() => SHA256.Create(), value).Dump("SHA256.Create()");
Hash(() => new SHA256Cng(), value).Dump("new SHA256Cng()");
Hash(() => new SHA256CryptoServiceProvider(), value).Dump("new SHA256CryptoServiceProvider()");
Hash(() => new SHA256Managed(), value).Dump("new SHA256Managed()");
"".Dump();
Hash(() => MD5.Create(), value).Dump("MD5.Create()");
Hash(() => new MD5Cng(), value).Dump("new MD5Cng()");
Hash(() => new MD5CryptoServiceProvider(), value).Dump("new MD5CryptoServiceProvider()");
"".Dump();
Hash(() => SHA1.Create(), value).Dump("SHA1.Create()");
Hash(() => new SHA1Cng(), value).Dump("new SHA1Cng()");
Hash(() => new SHA1CryptoServiceProvider(), value).Dump("new SHA1CryptoServiceProvider()");
Hash(() => new SHA1Managed(), value).Dump("new SHA1Managed()");
}
public static string Hash(Func<HashAlgorithm> algoFunc, string value)
{
try
{
using (var algo = algoFunc())
using (var stream = new MemoryStream())
using (var writer = new StreamWriter(stream))
{
writer.Write(value);
writer.Flush();
stream.Position = 0;
return BitConverter.ToString(algo.ComputeHash(stream)).Replace("-", "");
}
}
catch (Exception ex) { return ex.GetBaseException().Message; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment