加密Web.Config

28

24
重复什么?像这样的评论应该附带链接 :) - RYFN
1
@Zeus,没错,但是“相关”框中的前两个就可以了。 - H H
1
感谢所有的回复。我投票支持关闭。 - TheVillageIdiot
6个回答

19

以下是在没有任何编程的情况下加密web.config文件的命令...

加密命令:

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

用于解密

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

通过这些命令,您可以加密或解密整个部分。


1
不要在路径末尾加上反斜杠“\”。在我删除它之前,这对我没有起作用。 - user2444499
1
请确保使用管理员权限运行。 - marsze
当我以管理员身份启动cmd并运行命令时,它说“'aspnet_regiis'不被识别为内部或外部命令、可操作的程序或批处理文件。”当我进入路径C:\Windows\Microsoft.NET\Framework\v4.0.30319并打开文件aspnet_regiis.exe时,它会自动关闭。我该如何运行这个命令? - Irfan Y
您可以在 C:\Windows\Microsoft.NET\Framework64\v4.0.30319 找到 aspnet_regiis.exe。在 Windows 命令提示符 (cmd) 中执行 aspnet_regis.exe。您可以使用 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe" -pdf "Section" "不包括 web.config 的路径" - Icad

10
我认为有两种方法可以做到这一点:
使用aspnet_regiis使用DPAPIRSA,或者以编程方式进行
编程方式可能很方便,特别是如果您还喜欢加密app.config。
从我的使用经验来看,如果您编写自定义配置部分,则必须将包含该部分类的DLL安装到GAC中。对于我正在工作的项目,我基本上脚本化了以下方法:
复制配置DLL到GAC。
执行加密。
从GAC中删除配置DLL。
如果您只是加密连接字符串,则很可能不会出现问题。您还需要考虑是否要在机器范围内加密或针对特定用户帐户进行加密-根据您的情况,这两个选项都可能很有用。为简单起见,我坚持采用机器范围内加密。我提供的链接解释了两种方法的优点。

是的,把它变成机器范围内操作会更容易! - TheVillageIdiot
嗨,RichardOD,我的问题是...如果要以编程方式进行操作,何时需要加密和解密webconfig文件?请查看我在此链接中发布的帖子 --> http://stackoverflow.com/questions/25614737/encrypt-decrypt-web-config - Haminteu
1
做这件事的意义是什么?任何人都可以像我们加密一样轻松地解密连接字符串。 - markthewizard1234
2
@markthewizard1234 加密使用的密钥是机器特定的。因此,除非您可以访问服务器,否则无法加密它。请参见https://www.codeproject.com/Tips/795135/Encrypt-ConnectionString-in-Web-Config(问题和答案段落)。 - marsze
@markthewizard1234:任何拥有服务器管理员权限的人。 - Tim

4

该博客提到IIS管理器允许编辑加密部分。但是从IIS 7开始,这不再正确。运行时可以解密加密的web.config文件,但无法通过IIS管理器解密。 - Ganesh R.
谢谢@irwin,这是一个非常好的资源,可以进一步研究这个问题。 - TheVillageIdiot

2

在您的框架目录中使用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.

2

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接