
- UID
- 455
- 帖子
- 3
- 精华
- 0
- 积分
- 8
- 金币
- 3
- 威望
- 0
- 贡献
- 0
|
asp.net2.0如何加密数据库联接字符串3 T1 h* F; W3 i4 r' v7 |) v
在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:
& ~0 b5 ?3 {- L1.添加密钥
1 n2 { ~) ]) U: G, r, J执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp( o" X4 l3 g9 I/ b0 y
其中"hnlaw"为密钥名称
0 p/ R9 }* p% `2 @+ F3 R. K* G2.添加web.config节点
, X7 ?6 E$ c, Z& _, ^在web.config的<configuration></configuration>之间添加:
6 L+ n9 C9 h1 H) _<configprotecteddata>
5 _: p+ u+ g2 X <providers>
- f4 D$ j8 a1 [4 x% {/ s; n <add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and
# _3 r- F* E( l Z! i7 H4 adecrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0, ! [4 N+ x' b% ]5 g' O2 J
culture=neutral, publickeytoken=b03f5f7f11d50a3a" />; Q4 Q# H9 M$ G3 G, `/ [
</providers>
; c: Y/ n$ O1 O</configprotecteddata>
+ C; }5 F4 Y4 i+ s注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;: r/ p4 q2 a0 r# Q
3.加密web.config
5 H. V7 }, p3 y$ q/ j到网站根目录添加一个批处理文件enweb.bat,内容如下:
# b' q I' M$ [+ d" r; B; l@echo off/ l5 H6 w6 G: u3 M4 I6 p
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" -prov
' Y/ H F9 F# n% t+ q% r1 U! @3 T"hnlaw"
4 N+ }9 k* j+ n9 x7 M+ | c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs studio\donet2\hnlawyer" -prov
( y7 r( ?) U* ]! O" C" N"hnlaw"
7 u1 C3 s# z3 s" I, l3 Zpause
+ K; L' S2 E/ N. C- S% J! E注册上面的的路径和名称!3 q5 L! e3 ?! W. o$ I
运行后出现成功!
. U- l# p# Q3 C0 w2 w4.解密/ F. `4 X: q/ ]9 q A
同样到网站根目录添加一个批处理文件deweb.bat,内容如下:" Z/ e6 F+ g8 D
@echo off
1 F) ] p( j* B' P* t, Y2 Fc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer"" L0 X0 }+ E A" |$ H
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs studio\donet2\hnlawyer"
& s4 I: t$ o+ I# W0 \2 M- Epause
$ e1 }5 V9 J* j, r! {" R+ U, r最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成
) u( Y& k5 h: e7 G6 w, M6 q的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could 6 C0 I4 F% f6 Y: j1 ]5 G
not be opened.无法读取+ y0 W9 m: e/ F1 y9 A; `6 j
, O4 q! U% h1 W, i
这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现
8 c' }$ N+ u4 C' }# F5 j% ?- F价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可$ h( X9 V% S8 A" m, a5 }( t
到http://www.now.cn/vhost申请试试! 电话:0756-2623871 QQ: 168075865 MSN:north888@now.net.cn, S5 x5 {* _; G5 J& J% a
全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55 |
|