
- UID
- 455
- 帖子
- 3
- 精华
- 0
- 积分
- 8
- 金币
- 3
- 威望
- 0
- 贡献
- 0
|
asp.net2.0如何加密数据库联接字符串
9 G# V7 W' z4 x. L在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:. j% K/ R6 @6 l/ x# Z$ i
1.添加密钥
. `+ K' Y W9 L( X执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp
% P/ {) A( c8 x5 O m其中"hnlaw"为密钥名称* B- F& ]# R4 a, L A: r/ I7 ^* h" t; |
2.添加web.config节点& w8 V8 B6 q) b& L- k& `( N2 x) E
在web.config的<configuration></configuration>之间添加:$ H) B5 f0 Q" w) Y6 r: h! q. N
<configprotecteddata>
% E$ g0 Y( h) n; w% _% c1 R- l4 S <providers>
, ]$ V- F& N R. P0 Q! u6 \8 g6 Q+ ]1 d <add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and
; d# G# J: ^5 N: a) tdecrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0,
9 K( Z% h. ]/ ]culture=neutral, publickeytoken=b03f5f7f11d50a3a" />
7 w/ j! G% P0 G0 u, \" { </providers>/ r- J. E7 Y- r, w( H0 C
</configprotecteddata>
$ q1 x" N+ b8 K注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;
# ]3 h4 \6 l/ J7 M {7 v& X" Q3.加密web.config
- I G0 \$ `$ }: R8 E到网站根目录添加一个批处理文件enweb.bat,内容如下:
0 q. e7 y T+ W& B/ q@echo off; G- r& d; ~; F0 X* f: g; u
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" -prov / y* D5 g$ u; o7 L2 {
"hnlaw"
1 w& U1 Q8 v0 ]3 c% Q9 S c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs studio\donet2\hnlawyer" -prov 4 i7 D. z2 k) Y3 C/ \2 y
"hnlaw"
. o R( P: _5 ^! _, h) U7 Upause, J* G, b T+ t' E( i/ x8 u5 [
注册上面的的路径和名称!5 F S7 g9 v- k7 {
运行后出现成功!) `& P J0 i) b
4.解密) V* Q0 q, F; f- Q6 V
同样到网站根目录添加一个批处理文件deweb.bat,内容如下:) e2 [& o- H: V1 A
@echo off
9 a: }9 e; @. D# v. c/ }9 e- qc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer"
/ L2 v/ c1 s: ^0 a% p& U1 Yc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs studio\donet2\hnlawyer"
( c: ?/ ]- I4 ]* Q. {0 V" r& y4 Hpause$ z C& G7 K1 P
最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成
1 H% H) s! N7 z( \* X9 {的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could , z3 D+ X4 k. N; ^* c
not be opened.无法读取+ \% e$ L1 y; h3 z
! t; r, U9 Z. \ O2 Z- ^
这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现% v7 c2 h$ L0 @0 s& `
价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可
6 y, z. F" f; v+ b) G4 S0 ^到http://www.now.cn/vhost申请试试! 电话:0756-2623871 QQ: 168075865 MSN:north888@now.net.cn( o, }" ?4 S4 t% `
全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55 |
|