Cryptography Application Block

 在博客圆看到一些关于企业库的文章(可以看看这位大师写的http://terrylee.cnblogs.com/),然后自己实践了一下,发现博客中的某些地方不是很好理解,后来自己茅塞顿开了,特此记下

添加一个组件:Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll

 首先要加密和解密需要引入企业库中的名叫using Microsoft.Practices.EnterpriseLibrary.Security.Cryptography;

 1.介绍一下如何加密数据库连接字符串:

 private void CryptoConfig()

{

         Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ConfigurationSection section = config.ConnectionStrings;
             if ((section.SectionInformation.IsProtected == false) && (section.SectionInformation.IsLocked == false))
            {
                section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
                section.SectionInformation.ForceSave = true;
                config.Save(ConfigurationSaveMode.Full);
            }

}

如何在查看一下,项目中bin 目录下配置文件,你就会发现已经加密了。。。。

posted @ 2008-07-24 17:19  悍马奔野  阅读(259)  评论(0编辑  收藏  举报