回 帖 发 新 帖 刷新版面

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

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

    

[url=http://www.now.cn/indexr.php?r=!bbstoudeng]【在线QQ讨论群】[/url]

[url=http://www.now.cn/indexr.php?r=!bbstoudeng]
在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下

1.添加密钥
执行cwindowsmicrosoft.netframeworkv2.0.50727aspnet_regiis -pc hnlaw -exp
其中hnlaw为密钥名称

2.添加web.config节点
在web.config的configurationconfiguration之间添加
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
cwindowsmicrosoft.netframeworkv2.0.50727aspnet_regiis -pef system.webidentity ehs  studiodonet2hnlawyer -prov 

hnlaw
  cwindowsmicrosoft.netframeworkv2.0.50727aspnet_regiis -pef connectionstrings ehs  studiodonet2hnlawyer -prov 

hnlaw
pause
注册上面的的路径和名称!
运行后出现成功!
4.解密
同样到网站根目录添加一个批处理文件deweb.bat,内容如下
@echo off
cwindowsmicrosoft.netframeworkv2.0.50727aspnet_regiis -pef system.webidentity ehs  studiodonet2hnlawyer
cwindowsmicrosoft.netframeworkv2.0.50727aspnet_regiis -pdf connectionstrings ehs  studiodonet2hnlawyer
pause
最后就是要注意做完后找到cdocuments and settingsall usersapplication datamicrosoftcryptorsamachinekeys目录下,找到生成
的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider the rsa key container could 
not be opened.无法读取

[/url]

回复列表 (共2个回复)

沙发

沙发····

板凳

板凳··········

我来回复

您尚未登录,请登录后再回复。点此登录或注册