
- UID
- 455
- 帖子
- 3
- 精华
- 0
- 积分
- 8
- 金币
- 3
- 威望
- 0
- 贡献
- 0
|
asp.net2.0如何加密数据库联接字符串) e( |0 Y: x4 }3 V# X% W. |
在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:3 @4 W; [! B- s) h: c5 j2 M
1.添加密钥
: Q# F. g( S1 [9 Y' c8 B+ y& |执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp: c4 g! ^2 y" y3 k, [% h2 [
其中"hnlaw"为密钥名称6 \5 T' D8 O8 O* K2 x/ W
2.添加web.config节点- p+ L; W$ ?9 Z+ a; m4 x. I( t2 s
在web.config的<configuration></configuration>之间添加:4 F! t w- w a1 L7 R# f7 d* o
<configprotecteddata>& V5 E8 H- v) l% |* f$ R
<providers> k- o% `% c: I$ k
<add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and # Y' j; s; B) Y; u' {' s
decrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0, # l# d7 k0 P. E/ S7 ^
culture=neutral, publickeytoken=b03f5f7f11d50a3a" />, e* E: R' M5 T" U. w- r* h' S
</providers>
$ T, _) `0 M' B% Q</configprotecteddata>( S) s8 Y3 \) x7 F# M
注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;8 _& U" T* z+ H4 a. U" d
3.加密web.config! G5 G; I* R& @1 Z. [7 V
到网站根目录添加一个批处理文件enweb.bat,内容如下:/ J" m$ u7 P& o- t4 y
@echo off
6 d6 ^/ C) v* L7 ^5 L+ C3 c( ?; Bc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" -prov % [2 B0 \$ l. S) o' U% H
"hnlaw"' \) L1 z" w9 N; _1 I& k3 i" q
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs studio\donet2\hnlawyer" -prov 1 M) n$ w, x X2 `- |5 }
"hnlaw"
% d: I/ W0 I- |; L# npause. i2 d% V" C) i# a; I! Q
注册上面的的路径和名称!
5 S5 ?$ r6 c- p& V7 T( T运行后出现成功!# g& Q8 C6 D; W$ u: k
4.解密
' ~0 A& a; T1 D3 E/ S# d5 c4 K同样到网站根目录添加一个批处理文件deweb.bat,内容如下:
+ C! Y$ J! g* _+ B6 x) }; s" Y. t1 c@echo off
! l2 }' E1 ^+ J9 A3 k8 T. Uc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer"* e8 X. E8 v/ p) l( g
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs studio\donet2\hnlawyer"% } X9 _: h3 `
pause
) z6 [/ D. S" R( E Z2 ^8 w, d E最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成( }' }; R$ R* k/ l/ k' N: g
的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could
) K% D; Y) C1 v. ?not be opened.无法读取
# k# G1 f/ |' m' ~+ ~" I! ?$ f
4 ~7 i- D+ C1 ^( S. f" n8 @% G8 q这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现& O( ~) ?3 L* J+ u* J2 P( }: {) q0 W
价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可" O. l+ }+ s7 j8 \
到http://www.now.cn/vhost申请试试! 电话:0756-2623871 QQ: 168075865 MSN:north888@now.net.cn
8 Q0 ^5 a1 f3 S( A全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55 |
|