加密Web.Config
用于部署.NET和加密配置文件以进行部署的加密配置文件重复
在web.config文件中加密信息的最佳方法和工具是什么?
我相信有两种方法可以做到这一点:
使用DPAPI或RSA使用aspnet_regi,或以编程方式执行 。
编程方式可以很方便,特别是如果您还想加密app.config。
根据我使用它的经验,如果您编写自定义配置部分,则已将包含该部分的类的DLL安装到GAC中。 对于我正在工作的项目,我基本上编写了以下方法:
- 将配置DLL复制到GAC。
- 执行加密。
- 从GAC中删除配置DLL。
如果您只是加密连接字符串,那么这可能不会成为问题。 您还需要牢记是要在机器范围内加密还是在特定用户帐户加密 – 根据您的情况,这两个选项都很有用。 为简单起见,我坚持使用机器加密。 我提供的链接解释了两种方法的优点。
以下是无需编程即可加密web.config文件的命令…
用于加密
aspnet_regiis -pef "Section" "Path exluding web.config"
对于解密
aspnet_regiis -pdf "Section" "Path exluding web.config"
通过此命令,您可以加密或解密所有部分。
你试过这个: http : //weblogs.asp.net/scottgu/archive/2006/01/09/434893.aspx
在框架目录中使用aspnet_regiis工具:
-- CONFIGURATION ENCRYPTION OPTIONS -- pe section Encrypt the configuration section. Optional arguments: [-prov provider] Use this provider to encrypt. [-app virtual-path] Encrypt at this virtual path. Virtual path must begin with a forward slash. If it is '/', then it refers to the root of the site. If -app is not specified, the root web.config will be encrypted. [-site site-name-or-ID] The site of the virtual path specified in -app. If not specified, the default web site will be used. [-location sub-path] Location sub path. [-pkm] Encrypt/decrypt the machine.config instead of web.config. pd section Decrypt the configuration section. Optional arguments: [-app virtual-path] Decrypt at this virtual path. Virtual path must begin with a forward slash. If it is '/', then it refers to the root of the site. If -app is not specified, the root web.config will be decrypted. [-site site-name-or-ID] The site of the virtual path specified in -app. If not specified, the default web site will be used. [-location sub-path] Location sub path. [-pkm] Encrypt/decrypt the machine.config instead of web.config.
您应该从这里开始,易于理解,在MSDN中详细解释分步指南: 如何:使用DPAPI加密ASP.NET 2.0中的配置部分
使用aspnet_regiis.exe命令行工具
您还可以使用aspnet_regiis.exe命令行工具加密和解密Web.config文件中的部分,该工具可以在%WINDOWSDIR%\ Microsoft.Net \ Framework \ version目录中找到。
请看这里: http : //aspnet.4guysfromrolla.com/articles/021506-1.aspx 。