在web.config会存储一些敏感信息,比如connectionStrings或者appSettings,例如下面的配置信息。

<?xml version="1.0"?>
<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <connectionStrings>
      <add name="MyNwConnectionString" connectionString="Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;"/>
    </connectionStrings>
    <appSettings>
      <add key="User" value="myUsername"/>
      <add key="Password" value="myPassword"/>
    </appSettings>
</configuration>

加密web.config文件可以使用:

aspnet_regiis -pef section web-app-physical-dir

                    Encrypt the configuration section. Optional arguments:

                    [-prov provider] Use this provider to encrypt. 

运行下面的命令就会分别对connectionStrings的信息进行加密:

aspnet_regiis.exe -pef "connectionStrings" "C:\Test"

步骤截图

1.要进行加密的目录

asp.net如何为配置文件加密

2.使用aspnet_regiis对connectionStrings节点进行加密

asp.net如何为配置文件加密


3.加密后的connectionStrings节点内容

asp.net如何为配置文件加密


解密的命令如下

-pdf section web-app-physical-dir

                    Decrypt the configuration section.

aspnet_regiis.exe -pdf "connectionStrings" "C:\Test"


解密的截图

asp.net如何为配置文件加密

相关文章:

  • 2021-12-31
  • 2021-12-05
  • 2021-12-05
  • 2021-12-05
  • 2021-12-05
  • 2021-12-05
  • 2021-12-15
  • 2021-12-05
猜你喜欢
  • 2021-12-28
  • 2021-12-15
  • 2021-11-17
  • 2021-12-15
  • 2021-12-28
  • 2021-12-05
相关资源
相似解决方案