
- UID
- 455
- 帖子
- 3
- 精华
- 0
- 积分
- 8
- 金币
- 3
- 威望
- 0
- 贡献
- 0
|
asp.net2.0如何加密数据库联接字符串- r s, {9 s8 F# r0 t- n1 C
在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:
" f0 M, s) ^; D$ W2 m* ~1.添加密钥0 i) L- z0 b; M: m, \' p ]2 z& E
执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp8 q2 w5 Z+ `6 e% i
其中"hnlaw"为密钥名称
3 x4 k- m3 T& L! {: r, g2.添加web.config节点" b! N9 h- J2 P, E
在web.config的<configuration></configuration>之间添加:
+ ^7 N. h0 S4 @7 J" O8 ~<configprotecteddata>$ w, C. J% T: F' T
<providers>
7 m# k0 s- s7 R5 p, d- | g <add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and # D+ n& N! ~$ Y& R/ Z
decrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0,
. h6 r8 R a" w0 ~' @4 G# i- y1 gculture=neutral, publickeytoken=b03f5f7f11d50a3a" />6 x% d9 R2 w+ Z% b/ ^
</providers>
1 ~5 M' [& I; R1 C7 f! q3 w: Q) o</configprotecteddata>$ U2 D9 {4 R. Y Z
注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;/ I N# F L, \; z% E! T" W% }
3.加密web.config
# t3 b: M' c' E' u) ^9 Z* T2 u. k0 U到网站根目录添加一个批处理文件enweb.bat,内容如下:+ T# L! Z# i, O: [
@echo off
2 p* N- |! {1 Oc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" -prov 7 ]$ ?1 |$ f0 S( g! t: C7 G8 ^
"hnlaw"
' f' n v. q1 Q1 g c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs studio\donet2\hnlawyer" -prov
# N3 p" r7 o/ @"hnlaw"( h3 u- W: h5 r0 r; w" U
pause9 z7 z: F1 |2 r5 g' w* D6 I# D
注册上面的的路径和名称!
: ?! B) d6 S" Z( x运行后出现成功!
. f. u* w. x) Z' x4.解密
6 W* f( b5 Y3 ~同样到网站根目录添加一个批处理文件deweb.bat,内容如下:
! R9 H0 ~; A6 ^& ?: G@echo off8 B+ W0 { g0 }9 f
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer"
; Q; B* S W9 Ec:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs studio\donet2\hnlawyer"- v- Z+ g. T8 h( U0 G8 w
pause
% u% o# b! v5 D) Z最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成
( ]% {! t. O+ ?- Q3 L的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could
( z& a4 _1 {& g0 s. u' S( }. Mnot be opened.无法读取
8 d) B( ~/ p* k. ~5 X9 {( }
# ~) ], b" L: Y# h% ^! v这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现4 k1 Y' w! { w
价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可& ], h8 W1 | p8 D. e/ T6 \/ r
到http://www.now.cn/vhost申请试试! 电话:0756-2623871 QQ: 168075865 MSN:north888@now.net.cn
# s( u! g1 X6 K$ W全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55 |
|