Openssl允许进入和退出FIPS模式。 windows加密api和.net包装类是否具有类似的功能?
我想启用FIPS模式,签署文档,然后返回正常模式。
答案 0 :(得分:2)
不幸的是没有;至少,不是没有一些架构上的变化。
您可以通过设置注册表值来启用/禁用FIPS模式:
HKLM\System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy\Enabled (DWORD)
0被禁用,1被启用
但是,存在一些限制:一旦您将加密提供程序加载到您的进程中,它就会“记住”该进程剩余时间内该FIPS模式的状态。所以这样的代码可以工作:
(注意:两种情况都假设FIPS模式在开始时关闭)
static void Main(string[] args)
{
using (RegistryKey fipsAlgorithmPolicy = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy", true))
{
fipsAlgorithmPolicy.SetValue("Enabled", 1, RegistryValueKind.DWord);
}
SHA1 sha = new SHA1Managed(); // throws, which is what you want
}
但是这样的代码不会:
static void Main(string[] args)
{
SHA1 sha = new SHA1Managed(); // Does not throw, which is expected
using (RegistryKey fipsAlgorithmPolicy = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy", true))
{
fipsAlgorithmPolicy.SetValue("Enabled", 1, RegistryValueKind.DWord);
}
sha = new SHA1Managed(); // Also does not throw, which is a shame
}
为了让您的代码能够反映新状态,您必须重新启动您的流程。话虽如此,您可以做的是将执行加密例程的代码隔离到应用程序在设置FIPS模式后生成的“帮助程序”进程中。实现它会有点痛苦,但它允许您切换FIPS模式并使代码按预期运行。
答案 1 :(得分:0)
您可以在每个程序的基础上-在.NET运行时设置架构中将enforceFIPSPolicy设置为true
,以指定您要强制执行计算机配置要求,密码算法必须符合联邦信息加工标准(FIPS)。