
- UID
- 455
- 帖子
- 3
- 精华
- 0
- 积分
- 8
- 金币
- 3
- 威望
- 0
- 贡献
- 0
|
asp.net2.0如何加密数据库联接字符串0 Z) C2 l* x6 K* c3 Z! @! E' U& I j
在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:* R2 a% J0 ~. [3 L/ M; G
1.添加密钥$ E: m+ u& R K" U5 M! {0 d1 }
执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp6 n' p* B- ~& v" J7 p- n4 W I
其中"hnlaw"为密钥名称
7 ?2 d: Y5 F; H2.添加web.config节点
6 y/ n( ?7 `/ H8 F' ]在web.config的<configuration></configuration>之间添加:
+ J) t. h5 M) i7 [<configprotecteddata>9 k& u" R0 x) o% d4 l7 K
<providers>
8 u2 M @/ I# G, n" e0 W <add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and 1 X, T" R7 f# w8 ], v5 D& k
decrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0, . K# P$ K/ p3 c
culture=neutral, publickeytoken=b03f5f7f11d50a3a" />, J1 H# g7 P/ `4 ?/ r, o8 y+ T
</providers>5 @( {- n/ p7 N7 d8 C5 B
</configprotecteddata>3 y1 t0 U" g+ a
注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;& r/ x6 w: c5 w# p1 `: B+ u8 T
3.加密web.config2 K' q/ y$ `/ o. K, ?$ o
到网站根目录添加一个批处理文件enweb.bat,内容如下:
. B# `- b6 r8 f$ b3 R# ^' c3 w, ^@echo off; [+ L9 M9 l. Z
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" -prov $ p1 ~7 w9 ^; e9 _( ~( p
"hnlaw"
! a& o4 A* ~7 O1 @- { c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs studio\donet2\hnlawyer" -prov 6 g- `8 J9 o4 J$ S z" S
"hnlaw"
9 _ J) @7 j0 j7 g* Y9 I1 ^pause
! _; L6 r3 r1 t- V0 Q注册上面的的路径和名称!
& g8 O( w) i1 i7 B运行后出现成功!# r. _3 e+ k& r8 X
4.解密1 C# i7 }7 v m' h' c9 r* e3 B
同样到网站根目录添加一个批处理文件deweb.bat,内容如下:
# N( t6 W( X D3 d@echo off
h' ~/ Y a% R- {- k9 h7 _c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer"
% @: i) c. Z' a4 h* h4 ]# X3 Kc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs studio\donet2\hnlawyer", d& @8 b1 h: R- r) M( R5 [
pause- q' ?6 A1 @4 E4 y) l
最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成8 c2 V0 K( B: Z
的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could
# R; Z" ^( o% x! a+ _9 Znot be opened.无法读取
0 Y3 Y# n$ l+ R' y) n# p# Z' j: a
8 o5 ]# L0 L5 d* w5 q4 v% t# t这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现
* M. Z |7 x3 v价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可$ f0 h, a' n5 S' c/ J o1 i6 H% Z
到http://www.now.cn/vhost申请试试! 电话:0756-2623871 QQ: 168075865 MSN:north888@now.net.cn
S5 t1 M) S2 h5 E全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55 |
|