日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Enterprise Library 2.0 Hands On Lab 翻译(3):数据访问程序块(三)

發布時間:2023/11/29 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Enterprise Library 2.0 Hands On Lab 翻译(3):数据访问程序块(三) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

練習3:加密數據庫連接信息

通過該練習,你將學會如何去加密數據庫連接信息。

?

第一步

打開DataEx3.sln項目,默認的安裝路徑應該為C:\Program Files\Microsoft Enterprise Library January 2006\labs\cs\Data Access\exercises\ex03\begin,并編譯。

?

第二步 加密數據庫連接字符串

1.在Enterprise Library1.1中加密連接字符串,需要依賴于Cryptography Application Block.NET Framework2.0中已經內置了這項功能,通過Configuration命名空間下的一些類來完成,支持兩種類型的加密:

DPAPIProtectedConfigurationProvider:使用Windows Data Protection API (DPAPI)

RsaProtectedConfigurationProvider:使用RSA算法

2.選擇ProductMaintenance項目,選擇Project | Add Reference …菜單命令,在彈出的對話框中選擇.NET頁并添加如下程序集。

System.Configuration.dll

3.在解決方案管理器中選擇Program.cs文件,選擇View | Code菜單命令,加入如下命名空間。

using?System.Configuration;

4.在方法ProtectConfiguration中添加如下代碼。

static?void?ProtectConfiguration()

{

????
//?TODO:?Protect?the?Connection?Strings

????
string?provider?=?"RsaProtectedConfigurationProvider";

?

????Configuration?config?
=?null;

????config?
=?ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

?

????ConfigurationSection?section?
=?config.ConnectionStrings;

?

????
if?((section.SectionInformation.IsProtected?==?false)?&&

????????(section.ElementInformation.IsLocked?
==?false))

????
{

????????
//?Protect?(encrypt)?the?"connectionStrings"?section.

????????section.SectionInformation.ProtectSection(provider);

?

????????
//?Save?the?encrypted?section.

????????section.SectionInformation.ForceSave?
=?true;

????????config.Save(ConfigurationSaveMode.Full);

????}


}

?

第三步 運行應用程序

選擇Debug | Start Without Debugging菜單命令并運行應用程序,注意該示例和練習2中的示例是一樣的。在項目bin\Debug目錄中打開ProductMaintenance.exe.config配置文件,注意到連接信息已經變成了密文。

<?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?Instance"?/>

??
<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>xeuEp2HB0xd87DFM0p5UwO78QjRW6A/pb6kGJpS5Rl0F0jHAEPh8wz4Jroc1+/I7nvmsCo6a8wzju4Nyd5ZGF6KRZgx56P9wRgkUFtJPgDROrz1ASRSIrOfMjw4+1uedT+pl+IuF1EWgEH9Vb+/8A9xmbYWtMBAcR/f/quSC1nQ=</CipherValue>

??????????
</CipherData>

????????
</EncryptedKey>

??????
</KeyInfo>

??????
<CipherData>

????????
<CipherValue>DrwCnj8uCmkWOjLc2waTGX2pf8QKRFpegQbFv0zcVAwcCkZRvUVnIj9kXCLiIx+Pcbrz6H/fccbWxybAA+V7A4unJvDXegyZR1+dW7UqfDOAagTW67FC6iI3vatOpGCw30W+xpwhfgptCoFRNiCMWqxvpv++pywSK5SNfB7UZwpl90Q9dBHmmCIVyi/ZbS5JY2FLN68nRd9CHZmZLHv9opBm4DvMVdAXt7oKQ6tk9k4HJZzpUc1V8pWLQn7NQroA/4WpUDGGgk1gJ2HTBkP2L6wATzxTfQDgZbW/JIgrdollAQbO3/UEAvAnc0swoL/6BhWS5MW/9PxjuQK6GhsnSr4Dg7SEdsFPO2bTsAP/lAUeY5y9M3UxC1Q32IwMt8O4gz5ppNgYY7R8yKmvH7/S80/i61qJXvSJEQ/hQjx8V2R9okuBaN4XVgLUysmFWsOwxxHiGFyuSOECDWnr1c/5XwM7O85gVTzMELdM+N1jVFQTADXQmckOY1nZllRd3cA9CB1Qruqn/RxbGOFHT1F6y/4Cbfk7x1CKsmHx0iI0WNJ5iD3KYEq5kosGwWxrOI8C28BiXfEztwCzruSP6JpMbw==</CipherValue>

??????
</CipherData>

????
</EncryptedData>

??
</connectionStrings>

</configuration>


注意根據Hands On Lab給出的時間建議,做完以上三個練習的時間應該為30分鐘。

更多Enterprise Library的文章請參考《Enterprise Library系列文章

轉載于:https://www.cnblogs.com/Terrylee/archive/2006/10/06/Data_Access_Application_Block_HandsOnLab_Part3.html

總結

以上是生活随笔為你收集整理的Enterprise Library 2.0 Hands On Lab 翻译(3):数据访问程序块(三)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。