惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
V
V2EX
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
The Cloudflare Blog
T
Tailwind CSS Blog
H
Help Net Security
腾讯CDC
爱范儿
爱范儿
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
D
DataBreaches.Net
C
Check Point Blog
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

博客园 - 冰绿茶

解决Ehcache缓存警告问题 关于NHibernate、Castle和WCF做分布式事务时发生异常的解决办法 数据绑定控件和XmlDataSource控件结合使用,通过后台绑定Xml数据片段遇到的问题 微软StockTrader 2.03 学习笔记(8)--配置服务实现示例指南(四) 微软StockTrader 2.03 学习笔记(7)--配置服务实现示例指南(三) 微软StockTrader 2.03 学习笔记(6)--配置服务实现示例指南(二) 微软StockTrader 2.03 学习笔记(5)--配置服务实现示例指南(一) 微软StockTrader 2.03 学习笔记(4)--配置数据库生成工具介绍 SQLServer实战经验分享--ServiceBroker安全配置和使用示例 ASP.NET Trick文章系列--使用State Server管理Session状态的另类经济用法 微软StockTrader 2.03 学习笔记(3)--配置网站和配置服务在StockTrader中的使用示例 在数据库事务设计中经常会遇到的疑惑 微软StockTrader 2.03 学习笔记(2)--什么是配置网站和配置服务、配置存储库 微软StockTrader 2.03 学习笔记(1)--学习大纲整理 asp.net 2.0页面性能的考虑--异步页面处理模型 Asp.net 2.0 动态加载其他子目录用户控件问题 Web 下配置文件信息的读写 .net 2.0 中对配置文件的读写 Understanding ASP.NET Provider Model (Creating Custom Membership and Role Providers) - Part 3
ASP.NET 2.0加密网站配置文件中的信息 - 冰绿茶 - 博客园
冰绿茶 · 2006-02-21 · via 博客园 - 冰绿茶

加密网站中的配置信息,我们不需要写任何代码,也不需要修改任何代码,只需要使用 aspnet_regiis 工具修改配置文件即可.
比如我们有下面一个配置文件需要加密:
<configuration>
  <connectionStrings>
    <add name="SqlServices" connectionString="Data Source=localhost;
Integrated Security=SSPI;Initial Catalog=Northwind;" />
  </connectionStrings>
</configuration>

假设这个配置文件在 MyApplication 目录下。
加密命令
aspnet_regiis -pe "connectionStrings" -app "/MyApplication"

aspnet_regiis 命令在你安装的 .net Framework 目录下, 默认在:
C:\WINDOWS\Microsoft.Net\Framework\v2.0.*

加密后的效果:
<configuration>
  <connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
    <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
      xmlns="http://www.w3.org/2001/04/xmlenc#">
      <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
      <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
        <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
          <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
          <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
            <KeyName>Rsa Key</KeyName>
          </KeyInfo>
          <CipherData>            <CipherValue>0RU0XfRexc6aLFYZM+f+IWZVINqTZAAunysoVPv0dliPM72D
34MJ/gX7pzvhSJNqCLiXeyjsayse
12oAuF4rlIEraa/RHiqDKjqyJtRrRCiqnwqt5PET5LM9Q0aiT20Kpb2G2hn/0QB
7vKcWydboTdbwmUa7fXaQJhMcKaVI0mc=</CipherValue>
          </CipherData>
        </EncryptedKey>
      </KeyInfo>
      <CipherData>        <CipherValue>BPws3LIOuXhD0qDlfRMWDy9Xwn1jPHnMosKuVn3JVPW
KmD2h7hJo2BeTIjyIOAq/2J1saLDJm
JfgG85BEKfVUuNbMRg6czcgXHyOKeAHZgHzdw+d
zA8qEF/t7wITzuIQEslGK2WlUXNDFg4ZfsYDivmxy6xQh3Fvw4JOCHzLXg/
ZJrjYcHIk3I27oh/XuxtSQ0VNOl
gfSsM/MTGwB4tloELcRJ6Jm5u0dJA2fvmjpdc=
</CipherValue>
      </CipherData>
    </EncryptedData>
  </connectionStrings>
</configuration>

注意:为了避免一行太长,我这里把加密后信息加了几个回车符。

ASP.NET 在处理 Web.config 文件时会自动对该文件的内容进行解密。因此,
不需要任何附加步骤即可对已加密的配置设置进行解密,供其他 ASP.NET 功能使用或用于访问代码中的值。

如果你想修改这些配置信息,就需要解密这个文件,然后再加密。解密用  aspnet_regiis.exe 命令的 -pd 选项。
参考命令如下:

aspnet_regiis -pd "connectionStrings" -app "/MyApplication"

上面给的范例是 针对 IIS 的站点,如果你的站点是使用VS2005 的 ASP.net Development Server
则需要用 -pef 参数,当然 iis 站点也可以这么用

aspnet_regiis.exe     -pef "connectionStrings"     "D:\My2005Codes\WebTestCode\TestWEBSite"

说明:
-pef  对指定物理(非虚拟)目录中的 Web.config 文件的指定配置节进行加密。
对应的这个解密则是
-pdf 参数  对指定物理(非虚拟)目录中的 Web.config 文件的指定配置节进行解密。

参考资料:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/bdasamppet4.asp