简体   繁体   English

加密Web.Config

[英]Encrypting Web.Config

Duplicate of Encrypting config files for deployment .NET and Encrypting config files for deployment 用于部署.NET加密配置文件以进行部署加密配置文件重复


What is the best approach and tools for encrypting information in web.config file? 在web.config文件中加密信息的最佳方法和工具是什么?

Here are the commands to encrypt web.config file without any programming... 以下是无需编程即可加密web.config文件的命令...

For encryption 用于加密

aspnet_regiis -pef "Section" "Path exluding web.config"

For Decryption 对于解密

aspnet_regiis -pdf "Section" "Path exluding web.config"

From this commands you can encrypt or decrypt all the section. 通过此命令,您可以加密或解密所有部分。

I believe there are two ways of doing this: 我相信有两种方法可以做到这一点:

using aspnet_regiis using DPAPI or RSA , or doing it programmatically . 使用DPAPIRSA使用aspnet_regi,或以编程方式执行

The programmatic way can be handy, particularly if you also like to encrypt app.config. 编程方式可以很方便,特别是如果您还想加密app.config。

From my experiences of using this, if you write a custom configuration section, you have install the DLL containing the classes for that section into the GAC. 根据我使用它的经验,如果您编写自定义配置部分,则已将包含该部分的类的DLL安装到GAC中。 For a project I was working I basically scripted the following approach: 对于我正在工作的项目,我基本上编写了以下方法:

  • Copy config DLL to GAC. 将配置DLL复制到GAC。
  • Perform encryption. 执行加密。
  • Remove config DLL from GAC. 从GAC中删除配置DLL。

Chances are if you are just encrypting connection strings then this won't be a problem. 如果您只是加密连接字符串,那么这可能不会成为问题。 You also need to be bear in mind whether you want to encrypt on a machine wide basis or to a specific user account- both options can be useful depending on your scenario. 您还需要记住是要在机器范围内加密还是在特定用户帐户加密 - 根据您的情况,这两个选项都很有用。 For simplicity I stuck to machine wide encryption. 为简单起见,我坚持使用机器加密。 The links I have provided explain the merits of both approaches. 我提供的链接解释了两种方法的优点。

Use the aspnet_regiis tool in your framework directory: 在框架目录中使用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中的配置部分

Use the aspnet_regiis.exe Command-Line Tool 使用aspnet_regiis.exe命令行工具

You can also encrypt and decrypt sections in the Web.config file using the aspnet_regiis.exe command-line tool, which can be found in the %WINDOWSDIR%\\Microsoft.Net\\Framework\\version directory. 您还可以使用aspnet_regiis.exe命令行工具加密和解密Web.config文件中的部分,该工具可以在%WINDOWSDIR%\\ Microsoft.Net \\ Framework \\ version目录中找到。

Look here: http://aspnet.4guysfromrolla.com/articles/021506-1.aspx . 请看这里: http//aspnet.4guysfromrolla.com/articles/021506-1.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM