zoukankan      html  css  js  c++  java
  • ASP.NET应用程序中加密Web.config 转载

    ASP.NET应用程序中加密Web.config - 瑞志.net - 山林客

    上面是我的IIS配置,我在“默认网站”下新增了一个虚拟目录作为应用程序的根,路径在“F:\aspnet\chap01”,该目录下有一个 Web.config配置文件。现在我要加密这个配置文件中的<connectionStrings>节点,让我的数据库配置信息不容易直接 让人看到。

    <connectionStrings>
        <add name="myConnString" connectionString="server=A4D5DF939A4F4C2\SQLSERVER2;database=MYDATABASE;uid=sa;pwd=sasa"/>
    </connectionStrings>

    可以看到,这里我们直接将数据库的用户名和密码显示,如果我们直接将这个程序发布,那么别有用心的人就可以窥探到我们的数据库。

    我们执行下面的命令

    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis  -pe "connectionStrings" -app "/chap01" -prov "RsaProtectedConfigurationProvider"

    其中-pe表示我们要加密,-app后面指定了我们所要用到的应用程序

    ASP.NET应用程序中加密Web.config - 瑞志.net - 山林客

    加密后的<connectionStrings>节点

      <connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
        <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
          xmlns="http://www.w3.org/2001/04/xmlenc#">
          <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
          <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
            <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
              <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
              <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
                <KeyName>Rsa Key</KeyName>
              </KeyInfo>
              <CipherData>
                <CipherValue>djYj3i988FG5ED6wu04F75wthI8dwpVKholfpoiwc+L8JTw4cz/Y/76CdUqrYBqNQstTDkJsU8spKdiEKONNP+fslcTPAWM/YTkXLwKvmn5qywmUep02XfulaV+VWwJwfrH6arn/ElYTJ++jABO5P0DRnto6bPTGQj4XS9+bvoE=</CipherValue>
              </CipherData>
            </EncryptedKey>
          </KeyInfo>
          <CipherData>
            <CipherValue>7IhYh2NqR4xgLBvzEMNs8ZfBnpWOM8GoGKxCS8IabFA4uZj84gT0Z2MjBZGsZjKL7vpT49XvXhtKDlpJ/DOd6ArdtV+PJJRyhq2QRHb3Ba5XovT1+L1RfhDjy4tRgPzlZT6caNUPDiV4ej8NXSqS/f4FBBh8s8Htc76kppJkAB/F2mjauohipSnSnfCsJ8DcLqLkKBcOhq7EY9L7cKbvSNf3C2MHxguEywckuy7V8h4=</CipherValue>
          </CipherData>
        </EncryptedData>
      </connectionStrings>

    Web应用程序可以自动执行解密,所以我们在调用的时候并不用担心解密的问题,例如我们要查看数据库连接参数,可以直接使用:

        public string GetConnectString()
        {
            string GetConnectString = ConfigurationManager.ConnectionStrings["myConnString"].ConnectionString;
            return GetConnectString;
        }

     要解密Web.config中的加密字符串回明文显示,只需使用:

    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis  -pd "connectionStri
    ngs" -app "/chap01"

    文章来源:

    http://ruizhinet.blog.163.com/blog/static/992138282009017104809/

  • 相关阅读:
    Guru's Guide to SQL Server Architecture and Internals
    如何诊断修正17883,17884,17887,17888错误
    Debugging a SQL Server query with WinDbg
    Windbg调试Sql Server 进程
    SQL SERVER 技术博客 外文
    sql server book
    SQL Server Debugging with WinDbg – an Introduction
    Concurrency(Locking, Blocking and Row Versioning)
    如何自学Android, 教大家玩爆Android
    Storage protocol stacks
  • 原文地址:https://www.cnblogs.com/chjf2008/p/2100358.html
Copyright © 2011-2022 走看看