创意安天

 找回密码
 注册创意安天

asp.net2.0如何加密数据库联接字符串

[复制链接]
发表于 2010-2-10 09:16 | 显示全部楼层 |阅读模式
asp.net2.0如何加密数据库联接字符串

        【在线QQ讨论群】


在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:

1.添加密钥
执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp
其中"hnlaw"为密钥名称

2.添加web.config节点
在web.config的<configuration></configuration>之间添加:
<configprotecteddata>
  <providers>
   <add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and

decrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0,

culture=neutral, publickeytoken=b03f5f7f11d50a3a" />
  </providers>
</configprotecteddata>
注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;

3.加密web.config
到网站根目录添加一个批处理文件enweb.bat,内容如下:
@echo off
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs  studio\donet2\hnlawyer" -prov

"hnlaw"
  c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs  studio\donet2\hnlawyer" -prov

"hnlaw"
pause
注册上面的的路径和名称!
运行后出现成功!
4.解密
同样到网站根目录添加一个批处理文件deweb.bat,内容如下:
@echo off
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs  studio\donet2\hnlawyer"
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs  studio\donet2\hnlawyer"
pause
最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成
的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could
not be opened.无法读取



  
这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代网,时代主机智强商务C型 +.CN域名,原价1952元/年,现价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可到www.now.cn/vhost 申请试试!
发表于 2010-2-27 10:18 | 显示全部楼层
做广告的。。。。 不过可挺贵。。。 咱们这边 域名 + 百兆 的空间 也比他的便宜多了。。。
您需要登录后才可以回帖 登录 | 注册创意安天

本版积分规则

小黑屋|手机版|Archiver|创意安天 ( 京ICP备09068574,ICP证100468号。 )

GMT+8, 2024-5-18 14:55

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表