广告联盟网

 找回密码
 注册
查看: 947|回复: 0
打印 上一主题 下一主题

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

[复制链接]
跳转到指定楼层
1#
发表于 2006-5-23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
asp.net2.0如何加密数据库联接字符串

在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=&quot;hnlaw&quot; usemachinecontainer=&quot;true&quot; description=&quot;uses rsacryptoserviceprovider to encrypt and

decrypt&quot; name=&quot;hnlaw&quot; type=&quot;system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0,

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

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

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

&quot;hnlaw&quot;
pause
注册上面的的路径和名称!
运行后出现成功!
4.解密
同样到网站根目录添加一个批处理文件deweb.bat,内容如下:
@echo off
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef &quot;system.web/identity&quot; &quot;e:\hs  studio\donet2\hnlawyer&quot;
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf &quot;connectionstrings&quot; &quot;e:\hs  studio\donet2\hnlawyer&quot;
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目录
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|广告联盟网  

GMT, 2024-5-19 , Processed in 0.071411 second(s), 20 queries .

Powered by Discuz! X3.2

© 2005-2021 www.ggads.com GGADS 广告联盟网

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