泰仔在線

          java學(xué)習(xí),心情日記,繽紛時(shí)刻
          posts - 100, comments - 34, trackbacks - 0, articles - 0

          加密 web.config

          Posted on 2008-05-18 14:14 泰仔在線 閱讀(353) 評(píng)論(0)  編輯  收藏 所屬分類: .NET相關(guān)
          1、打開記事本,然后將下面的代碼復(fù)制到一個(gè)新文件中。
          <%@ Page Language="C#" %>
          <%
          Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
          %>

          保存 my.aspx 到你的web目錄 ,運(yùn)行一下窗體顯示 “ NT AUTHORITY\NETWORK SERVICE ”。成功!

          2、(關(guān)鍵一步)運(yùn)行cmd,執(zhí)行以下

          aspnet_regiis -pa "NetFrameworkConfigurationKey" "NT AUTHORITY\NETWORK SERVICE"
           

          說明:注冊(cè)默認(rèn)的 RsaProtectedConfigurationProvider 的RSA 密鑰容器,
          NetFrameworkConfigurationKey 是 RsaProtectedConfigurationProvider 的默認(rèn)provider成功!

          3、現(xiàn)在,可以加密web.config ,運(yùn)行:

          加密:aspnet_regiis -pe "connectionStrings" -app "/Myweb"
          說明:"connectionStrings" 是要加密的節(jié),"/Myweb"是的web目錄
          解密:aspnet_regiis -pd "connectionStrings" -app "/Myweb"

          成功!

          4、這樣就可以在程序里調(diào)用了(不用解密, 哈哈):
          ...
          string connstr= ConfigurationManager.ConnectionStrings["myConnstr"].ConnectionString.ToString();
          ...


          同樣的,也可以用創(chuàng)建自己的RSA 密鑰容器,如下:
            (1)、創(chuàng)建 "MyKeys" 密鑰容器,運(yùn)行:aspnet_regiis -pc "MyKeys" -exp 
          (2)、在web.config里加入以下:
          <protectedData>
          <providers>
          <add name="MyProvider"
          type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0. 0.0,
          Culture=neutral, PublicKeyToken=b03f5f7f11d0a3a,
          processorArchitecture=MSIL"
          keyContainerName="MyKeys"
          useMachineContainer="true" />
          </providers>
          </protectedData>

          保存。


          (3)、授予帳戶對(duì)計(jì)算機(jī)級(jí)別的 "MyKeys" RSA 密鑰容器的訪問權(quán)限,運(yùn)行:

          aspnet_regiis -pa "MyKeys" "NT AUTHORITY\NETWORK SERVICE"

          (4)、現(xiàn)在,可以加密web.config ,運(yùn)行:

          加密aspnet_regiis -pe "connectionStrings" -app "/Myweb" -prov "MyProvider"

          說明"connectionStrings" 是要加密的節(jié)"/Myweb"是的web目錄"MyProvider" 自己密鑰容器

          解密aspnet_regiis -pd "connectionStrings" -app "/Myweb" -prov "MyProvider"

          轉(zhuǎn)自:加密 web.config
          主站蜘蛛池模板: 宜城市| 房山区| 工布江达县| 鄂托克前旗| 夏邑县| 怀远县| 津南区| 阳江市| 房产| 饶河县| 夏邑县| 陕西省| 阿合奇县| 海门市| 雷州市| 万州区| 韶关市| 那坡县| 鄢陵县| 祁连县| 马尔康县| 金阳县| 龙海市| 满洲里市| 商南县| 阳江市| 鄂州市| 凤台县| 温泉县| 柞水县| 塔河县| 巨野县| 永清县| 安阳县| 铁岭市| 临澧县| 蒙自县| 清涧县| 彰武县| 新建县| 泉州市|