.Net 对webconfig进行加密解密

加密:

            // 打开该应用程序中的配置文件
            Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
            //在打开的配置文件中找到指定的节       
            ConfigurationSection section = config.GetSection("connectionStrings");
            if (section != null && !section.SectionInformation.IsProtected)
            {
                section.SectionInformation.ProtectSection("rsaprotectedconfigurationprovider");
                config.Save();
                Response.Write("");
            }

 

解密:

            Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
            ConfigurationSection section = config.GetSection("connectionStrings");
            if (section != null && section.SectionInformation.IsProtected)
            {
                section.SectionInformation.UnprotectSection();
                config.Save();
                Response.Write("");
            }

posted on 2013-06-19 02:35  大黑脸  阅读(341)  评论(0编辑  收藏  举报

导航