|

- UID
- 455
- 帖子
- 3
- 精华
- 0
- 积分
- 8
- 金币
- 3
- 威望
- 0
- 贡献
- 0
|
asp.net2.0如何加密数据库联接字符串7 l+ G: o7 B, T3 I
在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:1 @8 P0 J$ P# x* c% A+ X) O
1.添加密钥
! L+ v2 j. z6 D7 a$ N9 J执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp
; h) c7 b7 f7 w; C/ E# s其中"hnlaw"为密钥名称
@2 G R+ V5 g2.添加web.config节点
3 Q, l6 W5 R1 m# p, p在web.config的<configuration></configuration>之间添加:
K. R: x0 C- V" I3 M<configprotecteddata>
7 E9 C" y% \1 y! X; o" `7 u <providers>
3 ]' j+ N# `& k7 M- g$ m6 {8 |; ? <add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and " I, u/ M* ?; R1 f. Q& U* l
decrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0,
9 S7 T2 Q$ w. `culture=neutral, publickeytoken=b03f5f7f11d50a3a" />
( j9 a5 Z( K- x </providers>: K/ M0 M: g/ l* l% K: Z
</configprotecteddata>2 r k: C+ I( v& T9 V" c$ G" a$ P
注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;/ Z# f; i8 _# s
3.加密web.config8 t; P8 f" g- ^8 Y% C, i
到网站根目录添加一个批处理文件enweb.bat,内容如下:; i: S% ?4 Q: S
@echo off9 n% R1 a! E8 p7 i
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" -prov 9 a/ I9 O6 ~) D+ M( e
"hnlaw"8 [! g: [& |) e6 X! }( M0 M1 r
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs studio\donet2\hnlawyer" -prov
6 t! a: u% t8 \9 C3 F$ ~"hnlaw"
5 x7 {) _+ j) U3 Z1 dpause
( G. S6 ?5 Z% \5 v注册上面的的路径和名称!, V3 d/ e+ t6 A
运行后出现成功!
( I% w, u) l- y2 R$ i* \! S( e- u4.解密1 N5 f7 E9 @( P4 N
同样到网站根目录添加一个批处理文件deweb.bat,内容如下:) [8 e& E( J: t
@echo off
: C+ `& S0 X# \) ?( D- Qc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer"2 z R( A: l9 ~0 l6 X: k
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs studio\donet2\hnlawyer"3 G, _' ^4 W! z- p" m% q
pause
) Z& N4 d7 {+ S! m4 Z) N# ]最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成
1 l/ m8 U5 {6 z1 E2 U+ ?, k0 g3 x2 p的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could , N+ V) C2 i( Z# O$ r3 |
not be opened.无法读取
! H6 t: J0 s* ^5 H$ W * J( ]- f2 J. z, m) M: C7 r/ W* a
这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现
8 h* t7 N8 D& z1 L价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可
* b1 {: W8 [# d5 {9 z8 N6 t到http://www.now.cn/vhost申请试试! 电话:0756-2623871 QQ: 168075865 MSN:north888@now.net.cn8 e; E6 S" r5 ?+ P2 r! D6 i
全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55 |
|