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);
                }
            }
    

      

  • 相关阅读:
    Python上下文管理器
    面向对象(三)【类的特殊成员及高级特性】
    面向对象(二)【类的成员及修饰符】
    面向对象(一)【“类与对象”的概念及特性】
    leetcode【14题】Longest Common Prefix
    Spring Cloud之Zuul
    Spring Cloud之Hystrix
    SpringCloud之Eureka、Ribbon
    synchronized块中的wait()、nofity()、nofityAll()方法
    IP的分类以及子网划分、网络设置
  • 原文地址:https://www.cnblogs.com/colder/p/3273057.html
Copyright © 2011-2022 走看看