程序启动时或者调用AES类时(RijndaelManaged) 静态构造里面执行 “FipsAlgorithmPolicy.Repair()” 世界核平、可亲。
namespace My.Cryptography.Standard
{
using System;
#if NETCOREAPP
using System.Runtime.CompilerServices;
#endif
using Microsoft.Win32;
public static class FipsAlgorithmPolicy
{
#if NETCOREAPP
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static bool Repair()
{
RegistryKey policy = null;
try
{
policy = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy", true);
{
object value = policy.GetValue("Enabled");
if (!(value == null || value == (object)false || Convert.ToByte(value) == 0))
{
policy.SetValue("Enabled", 0);
}
}
return true;
}
catch (Exception)
{
return false;
}
finally
{
if (policy != null)
{
try
{
policy.Dispose();
}
catch (Exception) { }
}
}
}
}
}