如何对ConnectionString进行加密解码?
2014-07-17 14:46
120 查看
这个就不说了就是一个类
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 "解密失败"; } } }
相关文章推荐
- 简单 utf8 编码、解码,可用来对数据进行加密
- 如何使用Base64进行加密和解密
- 如何实现对数据库单个字段进行加密
- 如何对java的class类进行加密
- Delphi中如何进行BASE64解码
- 如何用asp进行base64加密
- 如何对sqlite3数据库进行加密
- javascript用escape编码后如何用php进行解码?
- 在 Java 中如何进行 BASE64 编码和解码(转)
- 实用命令:利用openssl进行BASE64编码解码、md5/sha1摘要、AES/DES3加密解密
- 在 Java 中如何进行 BASE64 编码和解码(转)
- 对utf-8如何进行解码
- 如何使用Base64进行加密和解密(续)
- 如何利Mcrypt扩展库进行加密和解密?
- 在 Java 中如何进行 BASE64 编码和解码
- 如何对所有存储过程进行一次性的加密?(来自CSDN)
- [愚翁专栏]如何使用Base64进行加密和解密
- 在 Java 中如何进行 BASE64 编码和解码(转)
- Windows XP 里如何对文件进行加密
- 如何对ASP页面进行加密