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

      

  • 相关阅读:
    JAVA for(i = 0; i<a.length; i++) 解析
    3.2.2多维数组 3.3 排序
    3.2数组
    字符串和数组
    2.7.3与程序转移有关的跳转语句
    2.7.2 循环语句
    读书共享 Primer Plus C-part 4
    Linux 批量修改文件名
    关于/usr/local/lib/libz.a(zutil.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC解决办法
    做一个有深度的程序猿
  • 原文地址:https://www.cnblogs.com/colder/p/3273057.html
Copyright © 2011-2022 走看看