zoukankan      html  css  js  c++  java
  • 加密Web.config 文件中的敏感信息

    为了提高应用程序的安全性,可以使用aspnet_regiis.exe对web.config文件中的节进行加密,并管理加密密钥.ASP.NET 在处理文件时对配置文件进行解密。
    确保计算机上已经安装了IIS,并且建立的ASP.NEt网站.
    (1)授予应用程序对 RSA 加密密钥的读取权限.因为ASP.NET 应用程序必须能读取用于加密的密钥,才能对 Web.config 文件中的已加密信息进行解密。Machine.config 文件中缺省指定了一个 提供程序, .. name="RsaProtectedConfigurationProvider" keyContainerName="NetFrameworkConfigurationKey" ..,即默认 RsaProtectedConfigurationProvider 提供程序使用的 RSA 密钥容器名为 "NetFrameworkConfigurationKey"。
    下面取得ASP.NET应用程序的标识,打开文本编辑器,然后将下面的代码复制到一个新文件getId.aspx中。在浏览器中查看,浏览器中将显示 ASP.NET 应用程序的模拟标识
    <%@ Page Language="C#" %>
    <%
    Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
    %>
    命令行下输入c:\>aspnet_regiis -pa "NetFrameworkConfigurationKey" "ZGW\ASPNET",这个命令授予ZGW\ASPNET 帐户对计算机级别的 "NetFrameworkConfigurationKey" RSA 密钥容器的访问权限。(相反的移除命令使用-pr参数)
    (2) -pe选项进行加密
    aspnet_regiis -pe "connectionStrings" -app "/MyApplication" 对connectionStrings节进行加密
    aspnet_regiis -pd "appSettings" -app "/MyApplication"对appSettings节加密
    ..
    (3)解密时使用-pd选项.
    (4)查看已解密的配置值
    打开文本编辑器,然后将下面的 ASP.NET 代码复制到一个新文件中。
     1<%@ Page Language="C#" %>
     2<%@ Import Namespace="System.Configuration" %>
     3<%@ Import Namespace="System.Web.Configuration" %>
     4<script runat="server">
     5
     6public void Page_Load()
     7{
     8  ConnectionStringsGrid.DataSource = ConfigurationManager.ConnectionStrings;
     9  ConnectionStringsGrid.DataBind();
    10
    11  Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
    12  MachineKeySection key = 
    13    (MachineKeySection)config.GetSection("system.web/machineKey");
    14  DecryptionKey.Text = key.DecryptionKey;
    15  ValidationKey.Text = key.ValidationKey;
    16}

    17
    18</script>
    19<html>
    20
    21<body>
    22
    23<form runat="server">
    24
    25  <asp:GridView runat="server" CellPadding="4" id="ConnectionStringsGrid" />
    26  <P>
    27  MachineKey.DecryptionKey = <asp:Label runat="Server" id="DecryptionKey" /><BR>
    28  MachineKey.ValidationKey = <asp:Label runat="Server" id="ValidationKey" />
    29
    30</form>
    31
    32</body>
    33</html>

    将看到加密的 Web.config 文件中已解密的值

  • 相关阅读:
    Firefox浏览器安装 Disable Javascript插件
    Web常见漏洞及修复建议
    查询公网出口IP
    jQuery jsonp跨域请求--转载自https://www.cnblogs.com/chiangchou/p/jsonp.html
    理解闭包 js回收机制--转载https://www.cnblogs.com/wangyingblog/p/5569745.html
    全面理解Javascript闭包和闭包的几种写法及用途--转载自https://www.cnblogs.com/yunfeifei/p/4019504.html
    什么是闭包?闭包的优缺点?--转载自https://www.cnblogs.com/cxying93/p/6103375.html
    JavaScript局部变量和全局变量的理解--转载自https://www.cnblogs.com/eric-qin/p/4166552.html
    好文收藏
    SQL In和Like 参数化
  • 原文地址:https://www.cnblogs.com/macro/p/693470.html
Copyright © 2011-2022 走看看