asp.net - 是否可以加密从 web.config 指定为 configSource 的配置文件?

标签 asp.net iis encryption web-config aspnet-regiis.exe

我的 web.config 中有一个自定义部分需要加密。此自定义配置部分使用 configSource 属性指向单独的配置文件(因为该文件不受源代码控制),我希望对这个单独的配置文件进行加密。我没有运气使用 aspnet_regiis.exe 来加密此部分。

我想要实现的目标可能吗?

我的 web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="protectedAppSettings" type="System.Configuration.NameValueSectionHandler, System,Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />       
    </configSections>       
    <protectedAppSettings configSource="config\EnvironmentConfigurations\ProtectedAppSettings.config" />
  </configuration>

我的自定义配置文件:

<?xml version="1.0" encoding="utf-8"?>
<protectedAppSettings>  
  <add key="XXX" value="xxx"/>
</protectedAppSettings>

我已将 aspnet_regiis 添加到我的路径中,以便我可以从站点的根目录调用它。这是我正在执行的命令:

aspnet_regiis -pef protectedAppSettings ""

从该命令获得的输出告诉我加密已成功

我找到了this link这表明它应该正常工作,但它不适合我..

最佳答案

这是因为我用来定义配置部分的类型。尽管没有文档证明这一点,但 NameValueSectionHandler 类型在用于配置源时似乎不会加密。解决方案是将类型更改为 System.Configuration.AppSettingsSection 并且加密工作正常

关于asp.net - 是否可以加密从 web.config 指定为 configSource 的配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40650793/

相关文章:

c# - 从 asp.net 代码隐藏执行 Javascript 函数?

c# - 如何处理/取消同一用户 asp.net 的并发请求

c# - 无法从列表中获取值以便设置网格 header 值 c#

php - MediaWiki (IIS) - CSS 加载不正确

java - 在 Spring Boot 应用程序中,您如何/如何存储应用程序 secret (密码、API KEY)

node.js - 尝试解密使用密码保护的私钥

javascript - 部分 View 中的明确值(多个)

IIS ISAPI 扩展枚举根 Web 服务器目录漏洞

asp.net - 使用 Asp.Net Web Api 实现 Angular 2

javascript - "Invalid AES Block Size"SJCL解密