首页 > 代码库 > 如何对ConnectionString进行加密解码?
如何对ConnectionString进行加密解码?
这个就不说了就是一个类
public static class EncryptionConfig { /* 加密配置节点 * Response.Write(EncryptionConfig.Encryption("connectionStrings")); * 解密配置节点 * Response.Write(EncryptionConfig.Deciphering("connectionStrings")); * 不影响读取 Response.Write(WebConfigurationManager.AppSettings[0].ToString()); Response.Write(WebConfigurationManager.AppSettings[1].ToString()); */ /// <summary> /// 加密配置节点 /// </summary> /// <param name="strSection"></param> /// <returns></returns> public static string Encryption(string strSection) { System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath); //在打开的配置文件中找到指定的节 System.Configuration.ConfigurationSection section = config.GetSection(strSection); if (section != null && !section.SectionInformation.IsProtected) { section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider"); config.Save(); return "加密成功"; } else { return "加密失败"; } } /// <summary> /// 解密配置节点 /// </summary> /// <param name="strSection"></param> /// <returns></returns> public static string Deciphering(string strSection) { System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath); System.Configuration.ConfigurationSection section = config.GetSection(strSection); if (section != null && section.SectionInformation.IsProtected) { section.SectionInformation.UnprotectSection(); config.Save(); return "解密成功"; } else { return "解密失败"; } } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。