
- UID
- 455
- 帖子
- 3
- 精华
- 0
- 积分
- 8
- 金币
- 3
- 威望
- 0
- 贡献
- 0
|
asp.net2.0如何加密数据库联接字符串1 X, i* x* X' [ I! m
在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:0 V# q2 `+ z9 \* e
1.添加密钥
, w2 W( ~1 g6 P% Y. H执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp
_: ~: c; ~. p" z其中"hnlaw"为密钥名称! h' E# A9 g8 U/ N6 c
2.添加web.config节点' {1 \3 M" [0 l
在web.config的<configuration></configuration>之间添加:
$ i( |2 }5 q9 t- a8 l/ K( c q<configprotecteddata>0 D- o r2 z: l2 w6 I
<providers>7 l1 \$ |9 y3 J" O7 ?! j
<add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and : N$ C5 \0 t" B
decrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0, + a5 o% @, V* H1 x2 B/ A* Q
culture=neutral, publickeytoken=b03f5f7f11d50a3a" />
: B. K5 u3 \. k0 w( {; q2 h3 b </providers>8 \2 t' X% A7 H. T9 J: H
</configprotecteddata>( }' e+ w6 f- g, t d
注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;- g& C5 }: w+ i6 Q
3.加密web.config
: A+ I1 i" x2 s y4 S; s4 A到网站根目录添加一个批处理文件enweb.bat,内容如下:
4 E& V% y) F/ u! Q, }@echo off
, U3 g: v0 y) ~% |% T$ I6 ]5 {% pc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" -prov ! n# |8 _3 X) r8 R, ^
"hnlaw"0 _/ w3 o9 m( a
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs studio\donet2\hnlawyer" -prov 7 @; w: q% M$ d2 C d; t
"hnlaw"9 t: v. W' [. i- {# t: ] x* ?1 v
pause+ m+ @8 p' O; Q8 I
注册上面的的路径和名称!
3 v8 p, V+ }6 H) S& s运行后出现成功!3 f& ?9 x( E1 ]5 f/ u- k: R
4.解密
3 a9 A* ~% V) i* Q( q# t3 h- T! @同样到网站根目录添加一个批处理文件deweb.bat,内容如下:
- k2 d! u4 @+ E@echo off3 Y( J! j& `5 W' Y* h+ B" n
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer"
7 d& l, I, w2 i+ I' l/ K. E/ yc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs studio\donet2\hnlawyer") j1 `& j- d i5 o) _. J+ E
pause* O) Z) ]$ d1 a+ ^ P" F6 @
最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成
I3 Q' A8 _/ z' l: w! Z: V的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could
+ d B! W, Y1 D9 q9 T, }) h' Vnot be opened.无法读取6 f' _; n) k; x/ x2 `' {2 ]
* K! ^, L- P: t
这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现; ?5 _/ d" X. }1 b
价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可
+ n- u6 ^4 T4 ]( q到http://www.now.cn/vhost申请试试! 电话:0756-2623871 QQ: 168075865 MSN:north888@now.net.cn {( t( f0 w9 K; W3 A% L) G& V
全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55 |
|