Enterprise Library for .Net Framework 3.5 – EntLib v4.1 是patterns & practices 小组为.NET Framework 3.5 开发一套企业库,目前最新版本为v4.1,共包括9个Application Block,包括数据访问(Data Access Application Block)、异常管理(Exception Handling Application Block)、数据验证(Validation Application Block)等等,对企业应用开发非常有帮助,也非常实用。

相关下载信息:
本文根据EntLib v4.1 的学习手册(Hands on Lab),演示如何加密配置文件中连接字符串。
1. 下面就可以打开项目 \Enterprise Library 4.1 HOL\CS\Data Access\exercises\ex03\begin \DataEx3.sln 开始我们的工作了。
2. 打开项目中的app.config 配置文件,检查数据库连接字符串是否正确,目前connection string是明文,尚未加密。

3. 加密数据库连接字符串
选择app.config 配置文件,使用Enterprise Library Configuration 工具打开。

如下图所示,选择Data Access Application Block,然后在属性窗口中,选择ProtectionProvider属性,并设置该属性为 RsaProtectedConfigurationProvider。保存后,重新回到app.config在Visual Studio 的编辑界面。

现在,你会发现配置文件中的connection string 字符串已经加密了。

但是,现在你运行范例程序,和前面一样,运行正常。