asp.net2.0如何加密数据库联接字符串
asp.net2.0如何加密数据库联接字符串在asp.net2.0中,发布网站时,加密web.config,这样可以有效保证数据库用户和密码安全,其步骤如下:x7a'O.C:E#I]Q6x/~
1.添加密钥Y#y7K5l n l2sVH
执行:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp7i ?Xq%r+s
其中"hnlaw"为密钥名称/S m?/r YV R w9g
2.添加web.config节点ZG)b3r"B_y!pK
在web.config的<configuration></configuration>之间添加:
<configprotecteddata>
<providers>
<add keycontainername="hnlaw" usemachinecontainer="true" description="uses rsacryptoserviceprovider to encrypt and
decrypt" name="hnlaw" type="system.configuration.rsaprotectedconfigurationprovider,system.configuration, version=2.0.0.0, c,K;aI5ba0O hH(h
culture=neutral, publickeytoken=b03f5f7f11d50a3a" />:~6J:fO&n%Xe
</providers>
</configprotecteddata>-^!P)i2xD:E9?n
注意:这里keycontainername="hnlaw"和name="hnlaw"分别表示你的密钥名称;
3.加密web.config L.^G9~;E;nv*OC
到网站根目录添加一个批处理文件enweb.bat,内容如下:+~pj!rC5R[
@echo off'zl:od Al;Z_(cn
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer" -prov ba\ DvB3kPs
"hnlaw"
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "connectionstrings" "e:\hs studio\donet2\hnlawyer" -prov
"hnlaw"
pause
注册上面的的路径和名称!
运行后出现成功!
4.解密
同样到网站根目录添加一个批处理文件deweb.bat,内容如下:\^P }r ]
@echo off)@'e]!m.@
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "e:\hs studio\donet2\hnlawyer"f ]-g-b Or+yQ+r
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis -pdf "connectionstrings" "e:\hs studio\donet2\hnlawyer"ItH|7l8n D
pausex8gwR/F
最后就是要注意:做完后找到c:\documents and settings\all users\application data\microsoft\crypto\rsa\machinekeys目录下,找到生成
的密钥文件(可按时间查找),给上network service可读取权限,不然会出现error message from the provider: the rsa key container could