C# ASP.NET加密-aspnet_regiis-服务器场
我们有使用“NT授权\网络服务”的网站 我们目前正在使用以下命令加密配置文件C# ASP.NET加密-aspnet_regiis-服务器场,c#,asp.net,.net,encryption,aspnet-regiis.exe,C#,Asp.net,.net,Encryption,Aspnet Regiis.exe,我们有使用“NT授权\网络服务”的网站 我们目前正在使用以下命令加密配置文件 aspnet_regiis -pc "NetFrameworkConfigurationKey" aspnet_regiis -pa "NetFrameworkConfigurationKey" "NT Authority\Network Service" aspnet_regiis.exe -pef "connectionStrings" "C:\WebAppLocation\Folder" 注意:我们没有使用“-
aspnet_regiis -pc "NetFrameworkConfigurationKey"
aspnet_regiis -pa "NetFrameworkConfigurationKey" "NT Authority\Network Service"
aspnet_regiis.exe -pef "connectionStrings" "C:\WebAppLocation\Folder"
注意:我们没有使用“-exp”。当我们使用“-exp”时,它不是在创建RSA密钥容器
如您所见,我们使用的是默认密钥-NetFrameworkConfigurationKey。我们的网站有一个负载均衡器。Webserver1(W1)和WebServer2(W2)可用
如果我遵循上述命令,我们将在W1和W2上使用单独的键。然而,该网站使用这种方法
这种方法足够吗?
它有什么缺点或安全漏洞吗?
它在任何情况下都会失败吗?
注意:机器密钥已添加到我们的web.config中。这两种配置中都是相同的。但是,我们的configProtectedData不在Web.Config中。另外,我认为NetFrameworkConfigurationKey在这两台服务器上都会有所不同
我已经阅读了以下msdn aricle,用于Web场场景中的加密。
您所做的一切都很好,但我建议您将
machinekey
放在machine.config
中,而不是web.config
中。此值通常不会经常更改,并降低了更改web.configs时发生意外更改的可能性
这还将允许您扩展未来的应用程序,而不会破坏越来越多的web.configs。我觉得您做的每件事都不正确。首先,这里有两个问题:
machineKey
相同aspnet\u regiis-pc
命令创建一个新的RSA密钥容器,失败的原因是您指定的容器名称已经存在,因为它是默认名称。此容器中的密钥对不可导出,因此需要创建一个新的密钥容器,并指定-exp
开关以指示密钥对可导出
aspnet_regiis -pc "MyDeploymentKeyContainer" -exp
然后将密钥导出到一个文件,包括私钥:私钥用于解密配置部分,以便web服务器需要它
aspnet_regiis -px "MyDeploymentKeyContainer" deploykey.xml -pri
现在将config部分添加到web.config并保存它
<configProtectedData>
<providers>
<add keyContainerName="MyDeploymentKeyContainer"
useMachineContainer="true"
description="Uses RsaCryptoServiceProvider to encrypt and decrypt"
name="DeploymentProvider"
type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</configProtectedData>
现在,您需要将应用程序部署到两台服务器上,并导入先前导出到文件中的RSA密钥容器。在每次服务器运行时向上复制文件:
aspnet_regiis -pi deploykey.xml
完成后,从服务器上删除该文件-您不希望它挂起。最后,将运行web应用程序的应用程序池的用户帐户授予两台web服务器上的密钥容器访问权限
aspnet_regiis -pa "MyDeploymentKeyContainer" SomeDomain\SomeAccount
我用这种方式解决了这个问题:
aspnet_regiis -pi "MyDeploymentKeyContainer" "c:\keys.xml"
aspnet_regiis -pa "MyDeploymentKeyContainer" SomeDomain\SomeAccount
aspnet_regiis -pi "MyDeploymentKeyContainer" "c:\keys.xml"