获得本站免费赞助空间请点这里
返回列表 发帖

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

asp.net2.0如何加密数据库联接字符串& l4 a* v1 }' W8 K" f
在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:
3 c  y6 u' g# _8 B, v1.添加密钥
1 @, C$ E1 |$ w执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp* r* |3 J7 Q* ]
其中"hnlaw"为密钥名称
# J5 V5 M3 P. h6 {2.添加web.config节点
  W! `; a' ^( q4 h  J: r4 s在web.config的<configuration></configuration>之间添加:: ]) l9 N6 V+ {, S5 D, P2 Q& _: _- H
<configprotecteddata>4 h+ Y+ m8 B! E: N( y
  <providers>: m. m1 h5 Z& {7 R2 L* q3 b% y7 o0 s+ l
   <add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and
$ E( Q6 D4 Z+ K! A- S% t; i! C- Odecrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0,
, d. L! [+ P9 ]6 M8 ~4 b5 Oculture=neutral, publickeytoken=b03f5f7f11d50a3a" />. C+ r: P6 l3 o- `' s' @$ h6 i
  </providers>- z4 f; s- U8 k( u. P1 Z
</configprotecteddata>
# t. O( W0 Y  L+ w注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;3 x7 G! X! p2 m6 |" D8 T- f
3.加密web.config; R7 g1 [( \4 |  U3 r! t) G. }! _
到网站根目录添加一个批处理文件enweb.bat,内容如下:
1 c/ ~1 r1 D0 A; Z& s" g8 w7 Y& [0 P@echo off
0 I5 q# S$ o, Ic:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs  studio\donet2\hnlawyer" -prov   C- W5 R8 ~: u
"hnlaw"
3 S4 D$ _4 R& q3 Q! t! W8 i8 }  c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs  studio\donet2\hnlawyer" -prov
* `6 M( v4 t& u( v. t"hnlaw"- r% E3 Q$ O. P  h
pause! ^3 G0 o* N# z/ s+ O3 h9 j% ]  p0 x
注册上面的的路径和名称!
  o$ ^% Q4 {& Q: b* u运行后出现成功!! D! u1 N4 N; a- A  e- @
4.解密; |5 ~$ X: j+ t8 t! E! L9 w
同样到网站根目录添加一个批处理文件deweb.bat,内容如下:* k% N+ ~1 J0 _- h+ A
@echo off% x- U$ D5 ]$ Q& @5 ?
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs  studio\donet2\hnlawyer"" g9 N: e# h8 J' ]
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs  studio\donet2\hnlawyer"
, I2 |" Z5 w$ K( }2 I# Q3 u) t5 Ypause
0 `: q. Q" k7 m最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成
% i1 X& Y. V+ j的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could
  U+ H  `" Q; W. znot be opened.无法读取
( l# J& g. d4 {1 |! l* g
2 _+ K+ g  ~* q: ?0 W- K, {; Q这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现+ M5 `/ R+ i6 A, T. _. }
价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可4 K* ]) p1 \( x, m/ J6 m, P
http://www.now.cn/vhost申请试试!     电话:0756-2623871   QQ: 168075865   MSN:north888@now.net.cn, E6 s' }9 ~. W0 W# y$ @7 K
全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55

返回列表
【捌玖网络】已经运行: