Is there an alternate hashing algorithm to MD5 for FIPS-enabled systems?

安稳与你 提交于 2019-11-28 09:43:21

MD5 is not FIPS compliant. You can use instead of the MD5 one of the following hashing algorithms:

When you enforce FIPS compliance in the Windows security policy settings, you're asserting that you are only going to use FIPS-certified encryption and hashing algorithms. MD5 is not one of these approved hashing algorithms, and that's why the exception is being thrown.

The workaround is simple: choose a different hashing algorithm. The .NET Framework provides plenty of other options in the System.Security.Cryptography namespace. Select one of the SHA family of algorithms. I can't imagine any reason you would have to use MD5 as opposed to one of the alternatives.

You can use MD5Digest from Org.BouncyCastle.Crypto.Digests

MD5Digest hash = new MD5Digest();

public byte[] Hash(byte[] input)
{
     hash.BlockUpdate(input, 0, input.Length);
     byte[] result = new byte[hash.GetDigestSize()];
     hash.DoFinal(result, 0);
     return result;
}

public string Hash(string input)
{
     var data = System.Text.Encoding.Unicode.GetBytes(input);
     hash.BlockUpdate(data, 0, data.Length);
     byte[] result = new byte[hash.GetDigestSize()];
     hash.DoFinal(result, 0);

     return Hex.ToHexString(result).ToUpper();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!