zoukankan      html  css  js  c++  java
  • 解决方案:System.InvalidOperationException: 此实现不是 Windows 平台 FIPS 验证的加密算法的一部分。

    System.InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.

    引发该问题的原因是系统启动了FIPS,导致.NET Framework平台中的MD5加密及其他一些加密方法需要调用FIPS验证,但FIPS又不支持这些方法,故引发如上异常。

    解决方法:

    注册表HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlLsaFipsAlgorithmPolicy项目中,将Enabled值设置为0即可

    也可以在程序启动时加入检查和修复的代码,如下

            /// <summary>
            /// 测试MD5加密可用性
            /// </summary>
            public static void GeneratingMD5Test()
            {
                try
                {
                    MD5CryptoServiceProvider get_md5 = new MD5CryptoServiceProvider();
                }
                catch (InvalidOperationException)
                {
                    CloseFIPS();
                }
                catch (Exception) { }
            }
    
            /// <summary>
            /// 关闭操作系统FIPS功能(该功能开启会导致.NET Framework中的MD5加密功能出现错误)
            /// </summary>
            /// <returns></returns>
            private static bool CloseFIPS()
            {
                bool res = false;
                try
                {
                    RegistryKey localMachine = Registry.LocalMachine;
                    RegistryKey FipsAlgorithmPolicy = localMachine.CreateSubKey(@"SYSTEMCurrentControlSetControlLsaFipsAlgorithmPolicy");
                    string[] vks = FipsAlgorithmPolicy.GetValueNames();
                    foreach (string k in vks)
                    {
                        if (k.ToUpper() == "ENABLED")
                        {
                            if (FipsAlgorithmPolicy.GetValue(k).ToString() != "0")
                            {
                                MessageBoxButtons mbs = MessageBoxButtons.OKCancel;
                                DialogResult dre = MessageBox.Show("报名系统运行时发生错误,是否尝试修复(会更改注册表项目)?", "提示", mbs);
                                if (dre == DialogResult.OK)
                                {
                                    FipsAlgorithmPolicy.SetValue(k, 0);
                                }
                                break;
                            }
                        }
                    }
                    FipsAlgorithmPolicy.Close();
                    localMachine.Close();
                    res = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format("修复失败,发生错误:{0}{1}{0}详细情况请查看日志文件",Environment.NewLine,ex.Message), "错误");
                    LogException(ex);
                }
                return res;
            }
  • 相关阅读:
    转:高效使用 SSH 的 16 个技巧
    关于flash的多文件上传的http头
    使用Xmind画流程图、脑图
    用html5+flash两种方案实现前端长文转图
    用“夜间模式”模式(javascript书签)浏览网页
    浏览器上传图片技术的一点分析
    需求管理的关键步骤其实只有一个
    基于Google GWT的图形编辑框架gwthtml5graph发布了!
    软件需求与天女散花
    你和软件需求,谁管谁
  • 原文地址:https://www.cnblogs.com/Vulpers/p/7770665.html
Copyright © 2011-2022 走看看