• 使用spring.net+nibernate时如何用aspnet_regiis加密数据库连接字符串



    使用spring.net+nibernate时数据库连接往往是放在一个 <db:provider ...  />字段中的

    不能使用aspnet_regiis直接加密


    解决办法是引入一个专门负责键值对应的配置节

    <section name="databaseSettings" type="System.Configuration.NameValueSectionHandler" />

    在这个配置节中声明重要的连接参数

    <databaseSettings>
         <add key="db.datasource" value=".\SQLEXPRESS; Integrated Security=true; AttachDbFilename=|DataDirectory|northwnd.mdf; User Instance=true;"/>
         <add key="db.user" value="springqa"/>
         <add key="db.password" value="springqa"/>
         <add key="db.database" value="Northwind"/>
    </databaseSettings>



    在 Spring.NET 中,通过 PropertyPlaceholderConfigurer 读取配置参数,以便在 Spring.NET 中使用
    
    

    <!-- Property placeholder configurer for database settings -->
     <object type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
        <property name="ConfigSections" value="databaseSettings"/>
    </object>

    最后,把 <db:provider ...  />字段中的内容改换成 以通配符的形式声明

    <db:provider id="SqlServerDbProvider" provider="System.Data.SqlClient" connectionstring="Data Source=${db.datasource};database=${db.database};uid=${db.user};pwd=${db.password};">
    </db:provider>


    这样加密的时候只要加密

    <databaseSettings>
         <add key="db.datasource" value=".\SQLEXPRESS; Integrated Security=true; AttachDbFilename=|DataDirectory|northwnd.mdf; User Instance=true;"/>
         <add key="db.user" value="springqa"/>
         <add key="db.password" value="springqa"/>
         <add key="db.database" value="Northwind"/>
    </databaseSettings>
    这段就行了,加密后的效果

    <databaseSettings 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>PtULk77o93K0Wf66BLm+6ljtChqAha1+fHeVpFboLUBzOGk9256pvpVxyjAbxnxWGBp6s6haCwZS+gofCXfCzycEIxiXCaxTHUhFiUagfutCEHlTg/TwqO0s6B3qvzSZG/rMdAZc4vGt8yOv+XiZHlG/FZoH1LUaZUM+MmRXcoY=</CipherValue>
              </CipherData>
            </EncryptedKey>
          </KeyInfo>
          <CipherData>
            <CipherValue>4F0up6tbkZ1cOxtCuKmLdAtjBFUFLKsGgkzeibWHVdmSgupgfM7cNXHY/c3Emm6z1v99pqJyEMO3DoCfZiEgdka3qldxNwC+KTFfZDvfYiNuHnFIUY3VjuPiWmeQ69DLF5454u3V3GctPYAVmE0lFc+PYYyEH4Tn4YO4VtiwhWkHRFcEvt7mk4Y+4/aw37d8rrJV9Sx6Z1uJ4isKbAy2DXxJ82QRkilMbl/B6r0+1f4xK3OGEkVL8PRL3B/BOGzXOtOwJckxSyKL8LBbmw8P0J+JoTnuwhO50jMjqROOWg2GVFZkTvwMLg==</CipherValue>
          </CipherData>
        </EncryptedData>
      </databaseSettings>

  • 相关阅读:
    Redis实战(十)Redis常见问题及解决方案
    小团队构建大网站:中小研发团队架构实践
    Asp.net core 3.0
    图解TCP/IP
    TCP/IP协议
    Grid画边框
    WPF常用方法,事件驱动和控件遍历
    WPF中的画图
    WPF中的常用类汇总:
    WPF中的VisualTreeHelper
  • 原文地址:https://www.cnblogs.com/rav009/p/5131182.html
Copyright © 2020-2023  润新知