程序启动时或者调用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) { }
                }
            }
        }
    }
}

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐