
- UID
- 455
- 帖子
- 3
- 精华
- 0
- 积分
- 8
- 金币
- 3
- 威望
- 0
- 贡献
- 0
|
asp.net2.0如何加密数据库联接字符串4 I7 |6 v1 @( P$ B7 C0 z
在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:
1 r; }* m+ p- ?) o9 ]! U5 o1.添加密钥
0 b- }7 n$ b) d( P执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp* v2 U0 a+ F. d. e
其中"hnlaw"为密钥名称8 s: D! n/ S4 Z0 H! @0 O
2.添加web.config节点/ z" g$ D. I, x
在web.config的<configuration></configuration>之间添加:
& u( V; Q% i- v' Q! m. R. c8 m<configprotecteddata>$ x- j3 c4 p: o( A
<providers># B( L$ a" V( p/ I$ E
<add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and
! c" E/ Y) x2 [! J; m( bdecrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0,
3 L; d2 C% c$ V) t+ [culture=neutral, publickeytoken=b03f5f7f11d50a3a" />/ G0 L, J, G5 e7 b! f/ R3 W6 Q& m2 k7 W
</providers>+ a0 e$ U- z' M. }. i" {) D* I+ w
</configprotecteddata># d. ?. U7 e2 _! D
注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;
5 t* g4 K1 w0 q3 u: |( }7 D3.加密web.config
# P& c/ e, y% b9 P: j到网站根目录添加一个批处理文件enweb.bat,内容如下:9 U! P" H4 S2 n% j( ~% K" `
@echo off
: g: |8 G! s6 }$ K. @: [5 bc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" -prov P6 b/ B( d" C( z& Y' k9 a9 D
"hnlaw"
; W, W/ q& |; w* q' t2 C c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs studio\donet2\hnlawyer" -prov
$ n1 v9 m. j( D$ T& ?"hnlaw"
$ U4 l4 e N9 } c \- d" \/ _' Qpause
U1 I; c- B0 R) E- t H注册上面的的路径和名称!& a* G* Z t4 p; J# [* f# \7 s1 |
运行后出现成功!
/ g$ u6 w' c5 I: F1 w4.解密) R: j# z, r0 J" j* G; \( \
同样到网站根目录添加一个批处理文件deweb.bat,内容如下:0 Q: {! |! \! H6 k
@echo off
6 \9 [" p- ^0 ~- X, o4 ]& p( `5 D, uc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer"
0 M( t- V! t# a; D+ oc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs studio\donet2\hnlawyer"
" n* @) G! M o- rpause, Q! l6 U' d6 |6 Y0 X
最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成
, h0 d$ a4 P4 O U% t+ L* `/ n# P& w o的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could " U( t6 E# G4 ^' K; Y
not be opened.无法读取
* N3 Z& [" h/ r* G/ _ $ g$ a% U' m! X* g/ {) P
这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现% L$ M1 ]; F! E, R& k( Q
价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可
" G0 u- V' \8 H* m: G7 ?! Q- F到http://www.now.cn/vhost申请试试! 电话:0756-2623871 QQ: 168075865 MSN:north888@now.net.cn8 o n* W' p. r1 Q4 q# B- s
全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55 |
|