首页 > 数据库技术 > 详细

EntLib 自动数据库连接字符串加密

时间:2015-01-16 18:25:39      阅读:262      评论:0      收藏:0      [点我收藏+]
 const string provider = "RsaProtectedConfigurationProvider";
                Configuration config = null;

                config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

                // 加密连接字符串

                ConfigurationSection section = config.ConnectionStrings;

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

                    (section.ElementInformation.IsLocked == false))
                {
                    section.SectionInformation.ProtectSection(provider);

                    section.SectionInformation.ForceSave = true;

                    config.Save(ConfigurationSaveMode.Full);

                }

这样控制台所在目录或者IIS发布目录下连接将是加密字符串.

如果报错,说明机器上没有RSA容器,可通过

aspnet_regiis -pc "MyKeys" -exp

aspnet_regiis -pa "MyKeys" "NT AUTHORITY\NETWORK SERVICE"

 

创建,具体参见:http://msdn.microsoft.com/en-us/library/2w117ede.aspx 

参考:http://www.cnblogs.com/Terrylee/archive/2006/06/05/Enterprise_Library_Encryption_ConnectionStrings.html

EntLib 自动数据库连接字符串加密

原文:http://www.cnblogs.com/tyb1222/p/4229172.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!