获得本站免费赞助空间请点这里
返回列表 发帖

asp.net2.0如何加密数据库联接字符串

asp.net2.0如何加密数据库联接字符串2 W. Q; A- j1 x
在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:
; ~5 T- g7 M5 G  z9 ~1.添加密钥
" C; W, P& ^) t* c9 u- v# d执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp6 x. T. s) C* R, E
其中"hnlaw"为密钥名称( U0 ]6 U# K3 E! t. c6 X
2.添加web.config节点
4 X/ D, C& q/ c! c1 E4 @# h  x% U在web.config的<configuration></configuration>之间添加:
! T$ {7 m& Y, A* l8 V! h<configprotecteddata>) k) U8 v! V4 x
  <providers>
( E) L  V8 F- ~% f$ |1 e+ p   <add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and   _9 z( ]* b: j6 |) O8 A, v' f
decrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0, 5 N3 Y  k% g3 a3 z+ U8 M
culture=neutral, publickeytoken=b03f5f7f11d50a3a" />
3 n2 H1 W9 B$ f$ f$ i1 D: e  </providers>! o% O+ p% C1 Z
</configprotecteddata>) A+ H/ d: w: N$ O# G# n$ X
注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;
, S, M$ Z+ y6 f2 Y% S/ s9 b3.加密web.config
- H! r5 ?* h9 W到网站根目录添加一个批处理文件enweb.bat,内容如下:
( |& u9 N& s; t  h: W@echo off: ?. K3 F- }0 P, t3 \2 Q
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs  studio\donet2\hnlawyer" -prov
0 j( o! l4 |  N. F"hnlaw"( e" o9 C/ H; c7 l
  c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs  studio\donet2\hnlawyer" -prov & F  Y2 w* H- x3 h2 S
"hnlaw"
, H0 G5 w! V1 X1 s5 Hpause) p8 m- G; \5 ]- {4 ~/ z, w6 _) z
注册上面的的路径和名称!
- g5 b3 i- {9 C# o/ R- n. ~运行后出现成功!
( O/ {' T% u0 f1 e4.解密
5 q# D+ d- q" x6 I7 P" I同样到网站根目录添加一个批处理文件deweb.bat,内容如下:
! @& L7 u3 i. J5 K8 k" I! R& G@echo off7 ^5 F) j$ S4 r& Q
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs  studio\donet2\hnlawyer"
. V+ L' s; f3 C: e' I2 f# Sc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs  studio\donet2\hnlawyer"7 t! Y! m( F; ?, A9 v4 x0 p
pause
, z6 P' Q0 S1 l) t$ g- G最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成$ x3 |4 @1 l* G( ^
的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could
* o* i* \. c0 S0 Enot be opened.无法读取4 R2 F$ j3 z* o& t

* r' e" \& [; _( r# O% I这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现
/ P3 z! g  q3 T) h& |% t8 o价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可
: s$ |  H, l9 h9 W) ^, i6 F( p( k! [http://www.now.cn/vhost申请试试!     电话:0756-2623871   QQ: 168075865   MSN:north888@now.net.cn. N! I$ `7 `/ I# u& s
全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55

返回列表
【捌玖网络】已经运行: