欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

关于XP\win7系统中安装.net4.0 程序运行版本出错的原因之一

程序员文章站 2022-05-04 20:06:30
...

解决“This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms”
还是装那台服务器,装好了IIS和ASP.NET,但在运行aspx页面时出现了异常:
异常信息: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.
上网搜索一下,有以下几种方案:
1.用组策略编辑器关闭FIPS:gpedit.msc,改成禁用

关于XP\win7系统中安装.net4.0 程序运行版本出错的原因之一

结果:我的本来就是禁用,此方案无效。
2.将DOTNET Framework停用FIPS。
(1)修改Web.config增加

<configuration>
    <runtime>
        <enforceFIPSPolicy enabled="false"/>
    </runtime>
</configuration>

结果:无效
(2)修改C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config,增加与(1)相同的内容
结果:无效
3.修改注册表:
(1):HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa:FipsAlgorithmPolicy=0;
(2):HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy:enabled=0;
结果:我的(1)是1,(2)本来就是0,把(1)改成0后,问题解决。

同时从网上找到了验证FIPS是否打开的代码(引用地址),贴在这里,如果执行结果中存在“N”的情况,则说明FIPS打开了:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Security.Cryptography;
namespace FIPS
{
    class Program
    {
        static void Main(string[] args)
        {
            Assembly core = Assembly.Load("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
            Assembly mscorlib = Assembly.Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
            Type[] subclasses = new Type[]
            {
                typeof(SymmetricAlgorithm),
                typeof(HashAlgorithm),
                typeof(AsymmetricAlgorithm)
            };

            Print(mscorlib, subclasses);
            Console.WriteLine();
            Console.WriteLine();
            Print(core, subclasses);

            Console.Read();
        }

        private static void Print(Assembly asm, Type[] subclasses)
        {
            string columnFormat = "{0,-35}{1,-15}{2}";
            Console.WriteLine("FIPS Compliant in {0}", asm.GetName());
            Console.WriteLine(columnFormat, "Name", "Compliant", "Subclass");

            foreach (Type type in asm.GetTypes())
            {
                foreach (Type subclass in subclasses)
                {
                    if (type.IsSubclassOf(subclass))
                    {
                        if (!type.IsAbstract)
                        {
                            string isCompliant = null;
                            try
                            {
                                Activator.CreateInstance(type);
                                isCompliant = "Y";
                            }
                            catch (TargetInvocationException)
                            {
                                isCompliant = "N";
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                            }
                            finally
                            {
                                Console.WriteLine(
                                    columnFormat, type.Name, isCompliant, subclass.Name);
                            }
                        }
                    }
                }
            }
        }
    }
}

修改前执行结果:

FIPS Compliant in mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77
a5c561934e089
Name                               Compliant      Subclass
DESCryptoServiceProvider           Y              SymmetricAlgorithm
DSACryptoServiceProvider           Y              AsymmetricAlgorithm
HMACMD5                            N              HashAlgorithm
HMACRIPEMD160                      N              HashAlgorithm
HMACSHA1                           Y              HashAlgorithm
HMACSHA256                         N              HashAlgorithm
HMACSHA384                         N              HashAlgorithm
HMACSHA512                         N              HashAlgorithm
MACTripleDES                       Y              HashAlgorithm
MD5CryptoServiceProvider           N              HashAlgorithm
RC2CryptoServiceProvider           N              SymmetricAlgorithm
RIPEMD160Managed                   N              HashAlgorithm
RSACryptoServiceProvider           Y              AsymmetricAlgorithm
RijndaelManaged                    N              SymmetricAlgorithm
SHA1CryptoServiceProvider          Y              HashAlgorithm
SHA1Managed                        N              HashAlgorithm
SHA256Managed                      N              HashAlgorithm
SHA384Managed                      N              HashAlgorithm
SHA512Managed                      N              HashAlgorithm
TripleDESCryptoServiceProvider     Y              SymmetricAlgorithm


FIPS Compliant in System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=
b77a5c561934e089
Name                               Compliant      Subclass
AesCryptoServiceProvider           Y              SymmetricAlgorithm
AesManaged                         N              SymmetricAlgorithm
ECDiffieHellmanCng                 Y              AsymmetricAlgorithm
ECDsaCng                           Y              AsymmetricAlgorithm
MD5Cng                             N              HashAlgorithm
SHA1Cng                            Y              HashAlgorithm
SHA256Cng                          Y              HashAlgorithm
SHA256CryptoServiceProvider        Y              HashAlgorithm
SHA384Cng                          Y              HashAlgorithm
SHA384CryptoServiceProvider        Y              HashAlgorithm
SHA512Cng                          Y              HashAlgorithm
SHA512CryptoServiceProvider        Y              HashAlgorithm

修改后的执行结果:

FIPS Compliant in mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77
a5c561934e089
Name                               Compliant      Subclass
DESCryptoServiceProvider           Y              SymmetricAlgorithm
DSACryptoServiceProvider           Y              AsymmetricAlgorithm
HMACMD5                            Y              HashAlgorithm
HMACRIPEMD160                      Y              HashAlgorithm
HMACSHA1                           Y              HashAlgorithm
HMACSHA256                         Y              HashAlgorithm
HMACSHA384                         Y              HashAlgorithm
HMACSHA512                         Y              HashAlgorithm
MACTripleDES                       Y              HashAlgorithm
MD5CryptoServiceProvider           Y              HashAlgorithm
RC2CryptoServiceProvider           Y              SymmetricAlgorithm
RIPEMD160Managed                   Y              HashAlgorithm
RSACryptoServiceProvider           Y              AsymmetricAlgorithm
RijndaelManaged                    Y              SymmetricAlgorithm
SHA1CryptoServiceProvider          Y              HashAlgorithm
SHA1Managed                        Y              HashAlgorithm
SHA256Managed                      Y              HashAlgorithm
SHA384Managed                      Y              HashAlgorithm
SHA512Managed                      Y              HashAlgorithm
TripleDESCryptoServiceProvider     Y              SymmetricAlgorithm


FIPS Compliant in System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=
b77a5c561934e089
Name                               Compliant      Subclass
AesCryptoServiceProvider           Y              SymmetricAlgorithm
AesManaged                         Y              SymmetricAlgorithm
ECDiffieHellmanCng                 Y              AsymmetricAlgorithm
ECDsaCng                           Y              AsymmetricAlgorithm
MD5Cng                             Y              HashAlgorithm
SHA1Cng                            Y              HashAlgorithm
SHA256Cng                          Y              HashAlgorithm
SHA256CryptoServiceProvider        Y              HashAlgorithm
SHA384Cng                          Y              HashAlgorithm
SHA384CryptoServiceProvider        Y              HashAlgorithm
SHA512Cng                          Y              HashAlgorithm
SHA512CryptoServiceProvider        Y              HashAlgorithm
相关标签: .net asp.net