zoukankan      html  css  js  c++  java
  • 加密 web.config

    目的:加密web.config中的敏感信息,使之不暴露给用户。
    步骤:
    1、建立虚拟目录WebSite,在该目录下建立一个test.aspx页面,代码为
    <%@ Page Language="C#" %>
    <%Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name);%>
    运行一下窗体显示 “ NT AUTHORITY\NETWORK SERVICE ”。成功!
    2、运行cmd,进入C:\windows\microsoft.net\framework\v2.0.50727目录,
    运行:aspnet_regiis -pa "NetFrameworkConfigurationKey" "NT AUTHORITY\NETWORK SERVICE"   
    说明:注册默
    认的 RsaProtectedConfigurationProvider 的RSA 密钥容器,NetFrameworkConfigurationKey 是 RsaProtectedConfigurationProvider 的默认provider。 成功!
    3、加密:aspnet_regiis -pe "connectionStrings" -app "/Myweb" 
    说明:"connectionStrings"
    是要加密的节,"/Myweb"是的web目录
    解密:aspnet_regiis -pd "connectionStrings" -app
    "/Myweb" 成功!  

     -------------------------------------------

    同样的,也可以用创建自己的RSA 密钥容器,如下:
    1、创建 "MyKeys" 密钥容器,运行: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、授予帐户对计算机级别的 "MyKeys" RSA 密钥容器的访问权限,
    运行: aspnet_regiis -pa
    "MyKeys" "NT AUTHORITY\NETWORK SERVICE" 
    4、现在,可以加密web.config ,运行: 
    加密:
    aspnet_regiis -pe "connectionStrings" -app "/Myweb" -prov "MyProvider"              
    明:"connectionStrings" 是要加密的节,"/Myweb"是的web目录,"MyProvider" 自己密钥容器            
    解密:aspnet_regiis -pd "connectionStrings" -app "/Myweb" -prov "MyProvider"  



  • 相关阅读:
    CSS 使DIV居中
    jsonlib 使用 转换JSON
    jquery autocomplete 自动完成 使用
    Sql server 实用技巧总结
    MvcHtml.DropDownList()用法
    日期时间正则表达式
    ASP.NET使用log4Net日志组件教程(每天产生一个日志及日志按大小切割)
    MvcHtml.ActionLink()用法
    给学弟的bitset使用整理
    2021 CCPC 广州站
  • 原文地址:https://www.cnblogs.com/xp/p/976595.html
Copyright © 2011-2022 走看看