|

- UID
- 455
- 帖子
- 3
- 精华
- 0
- 积分
- 8
- 金币
- 3
- 威望
- 0
- 贡献
- 0
|
asp.net2.0如何加密数据库联接字符串
, g5 f6 | p4 r3 ^在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:
: }; Z' w( ?4 Y: @! ~1.添加密钥
1 }9 g: E$ v( N$ H; d2 |2 @1 F! @( G执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp
7 [7 k8 d( L3 ^: j其中"hnlaw"为密钥名称
+ A/ p( X; W8 b" a5 k2 I2.添加web.config节点# A& m, X: |1 V$ x; i2 a& ^
在web.config的<configuration></configuration>之间添加:( u* |4 T) l5 ~" Y2 P" a3 C0 ^9 i
<configprotecteddata>6 r0 E0 @% W1 w @& y: c G, V
<providers>
I1 L4 n+ I! ~ <add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and " R0 \) K2 U8 }9 j3 R( G
decrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0,
1 h( E. E! i) X" e& h/ T9 I. Yculture=neutral, publickeytoken=b03f5f7f11d50a3a" />9 n& B- Q( a* s. C! ?$ |# [# k
</providers>
3 G3 K& ~9 e7 I i0 Z7 t' Q. S</configprotecteddata>( ?! j% P1 G b) Z/ m
注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;& W8 s- N6 F8 c
3.加密web.config
6 G7 ~+ f3 D# K5 i0 B5 X- E到网站根目录添加一个批处理文件enweb.bat,内容如下:
9 h% I% H$ h+ x% U& n@echo off0 P, ^ o* y G
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" -prov
5 q9 x) x- h1 y"hnlaw"
; }1 |' E' ?1 C# ]$ }0 l1 y+ v* q c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs studio\donet2\hnlawyer" -prov ( m3 B& C M/ Q& `, @
"hnlaw"
2 ^+ t# ?% v* Apause
. [6 }9 e7 a: }7 W注册上面的的路径和名称!2 ?" N5 E6 Q. c3 S. U- u2 L8 q
运行后出现成功!$ w7 X1 K; o" |: U* F6 C
4.解密7 F! s& [/ d. @9 n8 M" B
同样到网站根目录添加一个批处理文件deweb.bat,内容如下:+ S; G' i; J% `- {, p
@echo off1 Z7 h% M7 G+ i9 F" M
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" s& C0 R. V0 J$ s. Z
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs studio\donet2\hnlawyer"
. T2 B* r$ c: v3 D4 y' jpause
! c: E) A9 e, u最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成$ T% s. P1 o0 c8 S# w. g1 ]! Z8 c! P
的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could / y( n" T) F" p; r
not be opened.无法读取
" t/ [' s3 E, r / A% [% F/ r6 z3 y
这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现 Z. C; R* u3 b. T
价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可' _1 Z7 k: @% T1 e
到http://www.now.cn/vhost申请试试! 电话:0756-2623871 QQ: 168075865 MSN:north888@now.net.cn
* U- W. { `) |& B J. O$ _全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55 |
|