|

- UID
- 455
- 帖子
- 3
- 精华
- 0
- 积分
- 8
- 金币
- 3
- 威望
- 0
- 贡献
- 0
|
asp.net2.0如何加密数据库联接字符串
8 _: \( _% V$ J" r! A: @在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:
3 b7 D/ f, g! e( P+ O* }1.添加密钥
* z# i; e5 [) b, _4 X; ` ?执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp- r% O7 d4 i1 z. |
其中"hnlaw"为密钥名称
1 ^7 P. e3 r0 ], K" f2.添加web.config节点
1 B9 }% l& d0 f4 u [6 i$ i在web.config的<configuration></configuration>之间添加:
* d2 w5 e* h$ U y3 g<configprotecteddata>
g* d3 ]. O6 A; j, t <providers>! v8 ^- A& [& K% Y- V) _
<add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and
- c3 W' `& F2 u% A; {7 O+ Udecrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0, , K. p# E5 |1 n6 w
culture=neutral, publickeytoken=b03f5f7f11d50a3a" />7 |7 ]8 t( T) ]0 `5 j" m
</providers>
' m+ {* J9 Y6 q: o</configprotecteddata>) f9 a( D" J+ p
注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;
* F( o" S k5 M! ~# E" `3.加密web.config; Q0 M: W8 \( e) B* y3 X8 `
到网站根目录添加一个批处理文件enweb.bat,内容如下:) v6 r/ _( G4 W) K; q5 x* k
@echo off
) U% V; o; m* z: d# _& Ec:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" -prov
0 ?/ V4 V+ `/ ]( V"hnlaw"! y, P) P6 M( \( Y
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs studio\donet2\hnlawyer" -prov ) M; s) r! g# }9 m W" @
"hnlaw"
# W& a- u. D( w8 _, i* zpause
% w2 U- [( f% Y注册上面的的路径和名称!$ m9 R3 j6 j" J7 q
运行后出现成功!$ ]1 Q- r2 d; \3 |; V
4.解密
7 I: W( `% S/ B" r$ c' D% ?# w6 x同样到网站根目录添加一个批处理文件deweb.bat,内容如下: u5 k! Y: ~4 h3 K
@echo off1 i9 M# Z6 o8 p. j h
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer"
, [) A# c- U0 B+ Mc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs studio\donet2\hnlawyer"
, F0 Y% E) R- }; e, Y" r/ Z1 gpause E- G7 @; `/ N
最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成
6 w* b+ u% }6 A& s9 q: [的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could
$ D& z. G6 B" f, [( V& l! Lnot be opened.无法读取$ ]2 R% e: k1 r

. c8 r% D- R ~! y! c这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现
/ D8 ]) R/ d& N0 v/ R' l价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可5 v+ G6 } ~2 }$ H
到http://www.now.cn/vhost申请试试! 电话:0756-2623871 QQ: 168075865 MSN:north888@now.net.cn2 u: j; X5 ^4 O- d" W4 v5 A
全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55 |
|