Welcome

首页 / 软件开发 / .NET编程技术 / Enterprise Library 2.0中加密数据库连接字符串

Enterprise Library 2.0中加密数据库连接字符串2010-09-10 cnblogs terrylee看了SHY520写的关于Data Access Application Block的文章,写得不错,忽略了一点就是如何去加密数据库连接字符串,这儿我简单的介绍一下。我们知道,在Enterprise Library1.1中加密连接字符串,需要依赖于Cryptography Application Block。.NET Framework2.0中已经内置了这项功能,通过Configuration命名空间下的一些类来完成,支持两种类型的加密:

DPAPIProtectedConfigurationProvider:使用Windows Data Protection API (DPAPI)

RsaProtectedConfigurationProvider:使用RSA算法

下面来看一下具体的实现方法,假设已经有这样的一个配置文件:


<?xml version="1.0" encoding="utf-8"?>

<configuration>

<configSections>

<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />

</configSections>

<dataConfiguration defaultDatabase="QuickStarts" />

<connectionStrings>

<add name="QuickStarts" connectionString="Database=EntLibQuickStarts;Server=RJ-097;Integrated Security=SSPI;"

providerName="System.Data.SqlClient" />

</connectionStrings>

</configuration>

1.添加对System.Configuration.dll的引用