加密和部署的app.config [英] Encrypt and deploy app.config
问题描述
我已阅读并测试了很多找到加密和部署的app.config
到不同的机器上的最佳实践。在一般情况下,我想,以确保来自第三方的连接字符串的内容和应用程序部署到不同的机器。我会的不可以手动配置每台机器。
I read and tested a lot to find the best practice to encrypt and deploy an app.config
to different machines. In general, I would like to secure the content of the connection string from third parties and deploy the application to different machines. I will not configure each machine manually.
我知道有几种方法,如:
I know there are several ways like:
-
ASPNET_REGIIS(RSAProtectedConfigurationProvider, DPAPIProtectedConfigurationProvider)绑定到一台机器,用户或自定义。 RSA加密密钥。
Aspnet_Regiis (RSAProtectedConfigurationProvider, DPAPIProtectedConfigurationProvider) bound to a machine, user or custom. RSA encryption key.
System.Security.Cryptography.ProtectedData code>绑定到计算机或用户。
System.Security.Cryptography.ProtectedData
bound to a machine or user.
加密的app.config
在第一次执行。这是不安全的。
Encrypt the app.config
at the first execution. Which is not secure.
你有什么建议或什么是加密的的app.config
,并提供应用程序的不同机器通过安装或复制和最佳实践;粘贴
What do you recommend or what is the best practice to encrypt an app.config
and provide the application to different machines by a setup or with copy&paste?
推荐答案
第1步创建一个RSA密钥对
Step 1 Create an RSA keypair
aspnet_regiis -pc yourkey -exp
第二步的导出你的XML文件密钥
Step2 Export you key in XML file
aspnet_regiis -px yourkey keyfile.xml -pri
对于每个机
第三步:导入你的容器
aspnet_regiis -pi yourkey keyfile.xml (see step 2)
对于每个机
第四步:修改machine.config中(典型路径C:\ WINDOWS \ Microsoft.NET \框架[64 | 32]符\ v [版本] \配置)
Step4 Edit machine.config (canonical path C:\Windows\Microsoft.NET\Framework[64|32]\v[Version]\Config)
中添加部分的 configProtectedData STRONG>这下面元素,将 defaultProvider =YourProvider
add in section configProtectedData this below element and set defaultProvider="YourProvider"
<add name="YourProvider"
type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
description="Uses RsaCryptoServiceProvider to encrypt and decrypt for my infrastucture"
keyContainerName="yourkey"
cspProviderName=""
useMachineContainer="true"
useOAEP="false" />
然后你可以在一台机器进行加密和其他粘贴,记得一定要给权限的用户使用。
Then you can encrypt in a machine and paste in other, remember that must give privileges to users with
aspnet_regiis -pa yourkey [DOMAIN\USER]
Administrators组已授权。
The administrators group is already authorized.
有关更多信息<一个href="http://msdn.microsoft.com/en-us/library/yxw286t2(v=vs.90).aspx">http://msdn.microsoft.com/en-us/library/yxw286t2(v=vs.90).aspx
当然,这个步骤你可以把一个PowerShell /批处理文件
of course this steps you can put in a powershell/batch file
另一种方式的加密由code一个connectionStrings节是
Another way for encrypt a connectionStrings section by code is
var connectionStrings = ConfigurationManager.GetSection("connectionStrings")
if(!section.SectionInformation.IsProtected)
connectionStrings.SectionInformation.ProtectSection("YourProvider");
在连接和客户机/服务器方案我建议你,我在一个广泛的网络都采用的解决方案是不分配的连接字符串中的app.config但需要在服务连接的信息,可以是一个Web服务或用户认证后RESTful服务。
In a connected and client/server scenario I propose you a solution that I have adopted in a wide network is of not distribute connection string in app.config but of require the connection's information at a service that can be an web service or a RESTful service after the user authentication.
在步骤的详细Ø少就是这样
In step more o less is thus
- 验证用户
- 需要在提供服务方面的信息与用户名作为参数(HTTPS协议)
- 服务回报连接字符串
- 应用它连接在DB
通过这个解决方案,您可以选择,如果你有区域的服务器或服务器上的用户连接多个服务器
With this solution you can choose which server the user connects if you have regional server or more server
我希望有所帮助。
这篇关于加密和部署的app.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!