
- UID
- 455
- 帖子
- 3
- 精华
- 0
- 积分
- 8
- 金币
- 3
- 威望
- 0
- 贡献
- 0
|
asp.net2.0如何加密数据库联接字符串1 [3 d+ h d9 M2 \6 Z8 U7 R- }
在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:9 t& K& n p2 y+ \4 M" r
1.添加密钥
1 D, j5 [! ]1 z E& O/ _执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp
# m% Y; T. A- O' m- q其中"hnlaw"为密钥名称7 W* {$ i0 z" C- N( \; Y
2.添加web.config节点
d' J6 d* A1 }3 X在web.config的<configuration></configuration>之间添加:8 N$ d( P# L5 ]# x0 E+ f
<configprotecteddata>
M f. r+ ]) X4 _* \2 X <providers>
& H% K" I d# \ <add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and + T3 v9 h7 Y: u+ `( W
decrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0,
9 P/ E/ h2 U% s* U) r1 }culture=neutral, publickeytoken=b03f5f7f11d50a3a" />/ [1 w4 I9 _( x
</providers>
7 d1 r) ?! i: R7 D3 \+ L2 {6 n</configprotecteddata>
; f# P4 [: O* G注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;" ^: y# B* K% o" Y1 k6 W% u# \' v8 L/ F
3.加密web.config
2 h9 r5 L4 b; z s到网站根目录添加一个批处理文件enweb.bat,内容如下:
, g) t% O, O& t( X8 z@echo off6 L. g u/ q; w$ J& D8 f7 L
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" -prov , F3 V1 W6 d# Y5 h$ O
"hnlaw"6 Q) v7 t4 D) a
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs studio\donet2\hnlawyer" -prov
0 K" o$ q0 L; L) q"hnlaw"
2 d2 [' B5 C" m1 q# `pause ~) ]- c' y% l* e) x0 \/ @; U
注册上面的的路径和名称!
& b+ B% b2 J C5 `) u运行后出现成功!# D$ |% e, ?+ k/ M; o1 s: O7 O
4.解密; T" S: S8 m8 I" O9 K+ U3 r* K" f8 v
同样到网站根目录添加一个批处理文件deweb.bat,内容如下:5 T9 N8 `* |( L* \1 \$ d/ f g5 [6 g
@echo off
# I( C3 R" d" K5 U8 a; Vc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer"5 t: s& m5 s( O9 z2 B
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs studio\donet2\hnlawyer"
3 N' d8 `; v8 E& upause5 \) w/ |6 m+ ?/ _& u8 D
最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成
$ ?! ~& }1 G" Z$ m的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could # ?+ } Z- h+ E
not be opened.无法读取
" H. l- X3 A" ~# E& G, @7 k8 q
- r! x6 C& q& ^, I) E这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现
3 _4 j5 n; B( M9 _- P' x价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可- L! x l% Q3 k
到http://www.now.cn/vhost申请试试! 电话:0756-2623871 QQ: 168075865 MSN:north888@now.net.cn3 B$ W6 S" S8 P: z* ^
全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55 |
|