zoukankan      html  css  js  c++  java
  • Winform RsaProtectedConfigurationProvider 加密数据库连接字符串

    private static string _strProvider = "RsaProtectedConfigurationProvider";
    
    
            /// <summary>
            /// 提供加密的驱动
            /// </summary>
            public string Provider
            {
                get { return _strProvider; }
                set { _strProvider = value; }
            }
    
            /// <summary>
            /// 
            /// </summary>
            public ConfigSection() { }
    
            /// <summary>
            /// 加密配置文件节点
            /// </summary>
            /// <param name="strSectionName">节点名称</param>
            public static void EncryptConfigSection(string strSectionName)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                ConfigurationSection section = config.GetSection(strSectionName);
                if (section != null && !section.IsReadOnly() && !section.ElementInformation.IsLocked && !section.SectionInformation.IsProtected)
                {
                    section.SectionInformation.ProtectSection(_strProvider);
                    section.SectionInformation.ForceSave = true;
                    config.Save(ConfigurationSaveMode.Full);
                    ConfigurationManager.RefreshSection(strSectionName);
                }
            }
    
            /// <summary>
            /// 解密配置文件节点
            /// </summary>
            /// <param name="strSectionName">节点名称</param>
            public static void DecryptConfigSection(string strSectionName)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                ConfigurationSection section = config.GetSection(strSectionName);
                if (section != null && !section.IsReadOnly() && !section.ElementInformation.IsLocked && section.SectionInformation.IsProtected)
                {
                    section.SectionInformation.UnprotectSection();
                    section.SectionInformation.ForceSave = true;
                    config.Save(ConfigurationSaveMode.Full);
                    ConfigurationManager.RefreshSection(strSectionName);
                }
            }
    

      

  • 相关阅读:
    TP6|TP5.1 PHPoffice导出|导入
    centOS 7 环境搭建之安装 Redis
    centOS 7 环境搭建之安装 MySQL
    双向循环链表(DoubleLoopLinkList)
    双向链表(DoubleLinkList)
    可执行程序的编译过程
    C语言文件操作
    C语言跨平台时间操作计算时间差
    C语言线程安全问题
    C++类型双关
  • 原文地址:https://www.cnblogs.com/colder/p/3273057.html
Copyright © 2011-2022 走看看