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

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

asp.net2.0如何加密数据库联接字符串! T9 K# O2 i$ {, V: K3 o- ^0 }
在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:+ g2 K$ m9 q3 Z- d
1.添加密钥
: l& e. j. ~/ J7 ?+ s2 E执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp
0 {; f4 B. k+ W$ y% U! Y0 M其中"hnlaw"为密钥名称% F0 h6 T4 C" \3 e3 f" W: l
2.添加web.config节点! k+ |2 B  y/ r% x: {" n
在web.config的<configuration></configuration>之间添加:
. x4 O) Z5 G$ o<configprotecteddata>
, k& w8 _6 l. x2 ?# G+ s- N& y2 [  <providers>, ^/ v( D0 l& r! ~- [" e- L
   <add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and ; l1 a9 s  k" J# ]8 S1 {2 H
decrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0, & \7 q& r7 W# Q6 N
culture=neutral, publickeytoken=b03f5f7f11d50a3a" />; Y6 X" h- j  K8 d. O3 w  `
  </providers>7 x" E( W. P* G& N' G
</configprotecteddata>
1 z5 R1 t6 H+ z- Z% ?注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;8 B" O8 H$ t! d; J0 ]
3.加密web.config
, v6 _$ c0 t4 {  m到网站根目录添加一个批处理文件enweb.bat,内容如下:7 b2 G2 D2 s% J
@echo off
5 I+ Q! R& u& k& t( jc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs  studio\donet2\hnlawyer" -prov
+ m3 F' ]) K( `: A% {- \"hnlaw"$ p; V9 w, y8 p$ g0 U
  c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs  studio\donet2\hnlawyer" -prov
8 G+ e7 f. C# ?2 I"hnlaw"
. U/ D# j$ s% j) u. ?pause! M+ w: G# R8 H) e. W( y
注册上面的的路径和名称!
% v/ k1 ~" C5 T4 x4 \2 ]运行后出现成功!
% p. L4 _9 I# {: @% g! u* o! X4.解密, H- m' Z  e& t, @
同样到网站根目录添加一个批处理文件deweb.bat,内容如下:
, c# V# G/ h% u) r8 |5 p@echo off
. Z" v: p% J# c; [% o! {c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs  studio\donet2\hnlawyer"
) X! Z# ]" x5 U0 l+ w, pc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs  studio\donet2\hnlawyer"- e; u  d6 G8 Z3 L# E2 T  T
pause2 u7 L& p6 O+ g
最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成
* W2 e+ j$ ?/ @, I  p的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could
( o0 A: s1 H8 M3 v" V# _  M& Vnot be opened.无法读取
4 g; }2 e3 V( P! \$ A  h6 b: w& M& s! p! p+ w! r3 E( h
这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现6 X& S) S9 R4 r2 k$ V) c  j
价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可
7 I, n" d6 f% r+ yhttp://www.now.cn/vhost申请试试!     电话:0756-2623871   QQ: 168075865   MSN:north888@now.net.cn6 L/ I: W0 x7 ?0 x5 n* o/ x% }/ V
全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55

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