|

- UID
- 455
- 帖子
- 3
- 精华
- 0
- 积分
- 8
- 金币
- 3
- 威望
- 0
- 贡献
- 0
|
asp.net2.0如何加密数据库联接字符串5 ^- C) {- Z0 I9 n
在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:
* R" i2 r9 `; B1.添加密钥: i; ]; u% H% }& q5 O
执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp! f5 w* [/ n9 z. ?
其中"hnlaw"为密钥名称
+ u5 I% H* _' L8 c1 ?1 V1 a2.添加web.config节点
0 g7 M- N0 q0 g0 x在web.config的<configuration></configuration>之间添加:
# y' a; w0 L5 B( P<configprotecteddata>' k, @8 C+ L/ F
<providers>1 K, Y. c g# @0 K5 H$ \
<add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and ! F1 ?4 D' L* d5 _ w; i& @
decrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0, $ c5 J0 o5 P" Z5 U' c$ k4 Z
culture=neutral, publickeytoken=b03f5f7f11d50a3a" />) \+ @ a( V$ k; a' v7 Q8 Y/ K
</providers>
2 w. l' j% M: V8 ]# I1 M0 p</configprotecteddata>3 s4 I9 q# n0 }' y% F: j
注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;
x; D( v1 L: i0 r# l* j! G1 b1 A3.加密web.config2 _2 \' Y# P( z d* A
到网站根目录添加一个批处理文件enweb.bat,内容如下:
7 H. {8 y6 r6 q0 |6 x@echo off
) [8 z5 t- S$ R1 }) k, s r, yc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" -prov
: u0 f; N5 ?) U"hnlaw"
" X L" K" T0 r* j c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs studio\donet2\hnlawyer" -prov # W- J' @% _/ Q: x* |- [+ |1 E
"hnlaw"1 r2 z; D6 x: H3 X! g' Y/ k
pause+ \8 L7 a$ E6 ^8 g
注册上面的的路径和名称!
7 a+ I0 r z) x0 X运行后出现成功!
$ s4 s0 G; l. P. m1 q1 g: F4.解密0 J3 S4 _0 A2 ]. ]! d8 P8 z7 S/ O; G
同样到网站根目录添加一个批处理文件deweb.bat,内容如下:
9 P* O b8 t h3 s' O& p/ `@echo off
5 T8 \( Z) a) {9 M3 }! gc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer"
0 }+ x( ]! a. X ~, \9 s. Vc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs studio\donet2\hnlawyer") D( {. B( h8 m% s
pause2 @: H& C" H& L' J, T: [5 D
最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成! j) S% i3 L* m' J: W0 v, k; l
的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could 5 O/ S8 u R" P) H
not be opened.无法读取
& Q! Q8 }4 V' Z- T* I T0 S + Q5 j' K# g) q I" q2 G- w5 h0 u
这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现0 X0 `& _, u. e, }7 h
价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可8 L2 U$ U% f: l; `
到http://www.now.cn/vhost申请试试! 电话:0756-2623871 QQ: 168075865 MSN:north888@now.net.cn$ a* z% ?2 t3 m; k) b. A
全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55 |
|