我正在尝试设置一个 Web 应用程序以在 Windows 注册表FIPSAlgorithmPolicy
中设置为的环境中工作(特别是 HKLM/SYSTEM/CurrentControlSet/Control/Lsa)。1
启用此标志后,对该类的任何调用都MD5CryptoServiceProvider
将导致Invalid Operation Exception
抛出以下堆栈跟踪:
[InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.]
System.Security.Cryptography.RijndaelManaged..ctor() +10480142
System.Web.Configuration.MachineKeySection.ConfigureEncryptionObject() +439
System.Web.Configuration.MachineKeySection.EnsureConfig() +152
System.Web.Configuration.MachineKeySection.GetEncodedData(Byte[] buf, Byte[] modifier, Int32 start, Int32& length) +48
System.Web.UI.ObjectStateFormatter.Serialize(Object stateGraph) +381
System.Web.UI.Util.SerializeWithAssert(IStateFormatter formatter, Object stateGraph) +59
System.Web.UI.HiddenFieldPageStatePersister.Save() +89
System.Web.UI.Page.SaveAllState() +1117
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3864
根据我在本文中阅读的内容,您应该能够将以下内容添加到您的配置文件中以禁用算法检查:
<configuration>
<runtime>
<enforceFIPSPolicy enabled="false"/>
</runtime>
</configuration>
通过修改其 app.config,这对我在测试控制台应用程序中有效。但是,当修改 .NET 2.0 Web 应用程序的 web.config 时,它似乎不起作用。
对我来说有趣的是,即使我在实例化MD5CryptoServiceProvider
in 代码时捕获了所有异常,但它似乎甚至没有出现在我的代码的那部分。这是在我的测试应用程序中调用的代码:
protected string printSomething()
{
string toPrint = String.Empty;
try
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
toPrint = "Created algorithm.";
}
catch (Exception e)
{
toPrint = e.ToString();
}
return toPrint;
}
这是我在访问页面时看到的:
所以这带来了几个问题:
- 为什么 IIS 抛出 YSOD 而不是让我的应用程序捕获异常?
- 我需要做什么才能使我的网络应用程序能够使用
<enforceFIPSPolicy enabled="false"/>
?