介绍加密web.config配置文件之第2篇
如何加密.NET中web.config配置文件第一篇
在第一篇中介绍了用 DataProtectionConfigurationProvider加密web.config文件的方法
不过有一个缺陷,加密的文件只有在本机才能解密,如果有多台服务器的话,则需要每台机单独加密,因此不利于部署。
而利用RSAProtectedConfigurationProvider来加密就恰好可以解决这个问题。
本文就介绍一下如何利用RSAProtectedConfigurationProvider来部署多台服务器。
一 创建RSA 密钥
运行命令:aspnet_regiis -pc "LiuwuNetKeys" -exp
二 建立虚拟目录名称为EncryptWebConfig并添加Web.config文件如下:
XML-Code:
<configProtectedData>
<providers>
<add
keyContainerName="LiuwuNetKeys"
useMachineContainer="true"
description="Liuwu.net Keys"
name="LiuwuNetProvider"
type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</configProtectedData>
<connectionStrings>
<add name="Conn" connectionString="Data Source=liuwu;User ID=liuwu;Password=liuwu;" />
</connectionStrings>
主要是在config文件中加入configProtectedData配置节。