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

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

asp.net2.0如何加密数据库联接字符串
) _; h: l9 @, p) W& f在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:& E8 @* ^, J5 [; }* S% J6 O
1.添加密钥+ ]- d5 d4 ^# a) `, Q3 X
执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp
( E6 N) |9 i; g其中"hnlaw"为密钥名称
) |/ H2 G1 k# G  @2.添加web.config节点
+ @# G; [) B" V; C9 ]  c在web.config的<configuration></configuration>之间添加:2 }# G$ l+ F$ v8 h% L' E
<configprotecteddata>( `0 O  Z# w' T# t4 B: P6 O
  <providers>
  _% L! l( R5 {0 f9 H# P& p   <add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and
4 h- g5 u: a3 `  d! b/ I* |* ^decrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0, + `9 S4 i7 M( ]
culture=neutral, publickeytoken=b03f5f7f11d50a3a" />9 y  }/ @2 Q; @7 V/ ~$ j
  </providers>0 u- Z% ~  h3 H' B
</configprotecteddata>
4 y/ _3 n5 i: [注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;
. w& z% V3 T3 r/ o# L3.加密web.config; M  r- F3 p3 s! ^* [
到网站根目录添加一个批处理文件enweb.bat,内容如下:$ R  S5 T# H4 Y& A: ]
@echo off
9 h5 N' C7 f/ V1 Zc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs  studio\donet2\hnlawyer" -prov 8 |4 j  F% H; k' p# ]8 ~% |" K7 f
"hnlaw"
* G& [) W; E1 Z) ~$ Q2 p  c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs  studio\donet2\hnlawyer" -prov 8 d3 W) O" t# B' I# ?0 N
"hnlaw"
, Z) \  E' G8 R4 s' Dpause" B- j7 [  G* {
注册上面的的路径和名称!
/ z. `& G9 o5 m, }+ a* C0 U# q运行后出现成功!. W5 r9 r0 ]. F6 o" c
4.解密
+ |7 E% b- k5 U, f7 f( _% b同样到网站根目录添加一个批处理文件deweb.bat,内容如下:5 e! t9 s- K1 }1 n
@echo off
! c8 B% |$ t- x8 P4 }c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs  studio\donet2\hnlawyer"& ~( u, t, w& \7 {; o" p
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs  studio\donet2\hnlawyer"% E2 A& a( s+ }( b2 q! d  ~2 ]# D
pause
1 A* T6 T7 J, ^1 v最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成
$ }4 _  A" H! R/ G- R* w的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could 8 }& X; z9 U5 e
not be opened.无法读取. `$ ^% m9 u! g# ]6 I6 B/ g

% S9 _9 d9 o: D这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现
9 [2 |, h" f; A1 Z) G) s" a5 d) Y价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可* h1 @- _& b1 W+ B  n
http://www.now.cn/vhost申请试试!     电话:0756-2623871   QQ: 168075865   MSN:north888@now.net.cn: x- f" H" o* L; d* N
全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55

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