|

- UID
- 455
- 帖子
- 3
- 精华
- 0
- 积分
- 8
- 金币
- 3
- 威望
- 0
- 贡献
- 0
|
asp.net2.0如何加密数据库联接字符串
( }7 O8 B* ]( P/ }) u$ o1 O s& ]9 p在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:5 O1 V1 P' r5 m4 Y r4 Z/ H# n
1.添加密钥
9 H! P# E' t/ U5 z2 M% i# c( c执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp
m+ c! E2 e3 N7 l其中"hnlaw"为密钥名称
2 i# E2 R, m8 x+ G8 [3 K1 P2.添加web.config节点
y6 G9 D$ |3 ]8 ?; z2 e在web.config的<configuration></configuration>之间添加:4 n2 {; g) M0 W# {5 [
<configprotecteddata>
$ w. {6 d/ o; U" e3 c. ] <providers>% j: V7 G* L+ d/ x8 E
<add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and
5 q) u* f" F2 E+ K/ A1 ?decrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0,
( c/ B. u: q! G! P! v$ E8 a. z; fculture=neutral, publickeytoken=b03f5f7f11d50a3a" />
/ R5 C$ ~! D* X/ K </providers>
% C1 S4 x3 q" U: @9 t! Q</configprotecteddata>1 P7 g: b- W: O0 ^( y' w2 i0 M
注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;( ]- ?$ q9 R" A# d3 u. q
3.加密web.config# q4 p6 z- ]7 u- |+ J+ |; _
到网站根目录添加一个批处理文件enweb.bat,内容如下:
% ^- P. \4 s S@echo off
5 U7 f8 ]% O7 s0 Z3 e( d: Wc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" -prov W* r; K7 ]. Z8 a, b
"hnlaw"
. W1 h8 \0 b$ B( @+ t c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs studio\donet2\hnlawyer" -prov % E+ w5 n; _& A. ~9 m7 q; `! i
"hnlaw"6 h+ H. R7 p2 K/ i1 T
pause
) W* z) m" f5 e) \注册上面的的路径和名称!+ q* c( v5 q3 X+ X* s
运行后出现成功!6 \- v! K U$ d1 l! ^# T" {6 R
4.解密5 E% y8 k( z" r- o3 ]. k* e
同样到网站根目录添加一个批处理文件deweb.bat,内容如下:& L) r! Y* S. l' P) \% h
@echo off
$ t, t% y. u. U( o& g* q& dc:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer"' p5 y% A/ S! v8 Z
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs studio\donet2\hnlawyer"5 ?8 q3 _1 n1 Q7 |1 G- b% b
pause
* T1 Y* H2 C, S8 X8 g& W最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成. [( j) A; |' g( Z
的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could / o0 F# l9 t) @; _
not be opened.无法读取$ L9 K5 W. N' |2 f. ]' x6 z4 A# c
: n! N4 s! X' \- z# M* {
这样可能会出现,如果没有自己的服务器,没有权限修改machinekeys目录顺便向你推荐一款高速稳定的时代互联智强商务C型 +.CN域名,原价1952元/年,现
* q* o' z: M3 ?4 F价只需1588元/年,还免费送域名,CDN网站加速器 送繁简通网络简装版 ,联付宝网上支付,我觉得特值,特向大家推荐!有兴趣的朋友可7 @$ g2 g/ _0 L( G0 ?$ }/ f
到http://www.now.cn/vhost申请试试! 电话:0756-2623871 QQ: 168075865 MSN:north888@now.net.cn) D5 b9 n8 V$ m, [
全球免费咨询电话 http://www.now.cn/callcenter/call.net?LineName=55 |
|