国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > C# > 正文

C#加密app.config中連接字符串的方法

2019-10-29 21:40:44
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

這篇文章主要介紹了C#加密app.config中連接字符串的方法,涉及C#配置文件加密的相關(guān)實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了C#加密app.config中連接字符串的方法。分享給大家供大家參考。具體如下:

連接字符串中包含數(shù)據(jù)庫(kù)的訪(fǎng)問(wèn)信息,帳號(hào)和密碼,因此一般不以明文顯示,本代碼用來(lái)加密連接字符串。

 

 
  1. public static class EncryptConnection 
  2. public static void EncryptConnectionString(bool encrypt) 
  3. Configuration configFile = null
  4. try 
  5. // Open the configuration file and retrieve the connectionStrings section. 
  6. configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 
  7. ConnectionStringsSection configSection = configFile.GetSection("connectionStrings") as ConnectionStringsSection; 
  8. if ((!(configSection.ElementInformation.IsLocked)) && (!(configSection.SectionInformation.IsLocked))) 
  9. if (encrypt && !configSection.SectionInformation.IsProtected) 
  10. //encrypt is false to unencrypt 
  11. configSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); 
  12. if (!encrypt && configSection.SectionInformation.IsProtected) 
  13. //encrypt is true so encrypt 
  14. configSection.SectionInformation.UnprotectSection(); 
  15. //re-save the configuration file section 
  16. configSection.SectionInformation.ForceSave = true
  17. // Save the current configuration. 
  18. configFile.Save(); 
  19. }  
  20. catch (System.Exception ex) 
  21. throw (ex); 
  22. finally 

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 沙洋县| 扎兰屯市| 咸宁市| 水城县| 五家渠市| 沾益县| 眉山市| 盘山县| 九龙县| 鄂尔多斯市| 昌都县| 青铜峡市| 突泉县| 建湖县| 武城县| 金堂县| 岳阳市| 许昌市| 繁昌县| 介休市| 绥德县| 镇平县| 长治县| 若尔盖县| 环江| 青阳县| 白河县| 肥乡县| 驻马店市| 子洲县| 廉江市| 浪卡子县| 大英县| 句容市| 永新县| 扎兰屯市| 始兴县| 宁陕县| 阿克陶县| 会同县| 类乌齐县|