Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. static void ToggleConfigEncryption(string exeConfigName)
  2. {
  3. // Takes the executable file name without the
  4. // .config extension.
  5. try
  6. {
  7. // Open the configuration file and retrieve
  8. // the connectionStrings section.
  9. Configuration config = ConfigurationManager.
  10. OpenExeConfiguration(exeConfigName);
  11.  
  12. ConnectionStringsSection section =
  13. config.GetSection("connectionStrings")
  14. as ConnectionStringsSection;
  15.  
  16. if (section.SectionInformation.IsProtected)
  17. {
  18. // Remove encryption.
  19. section.SectionInformation.UnprotectSection();
  20. }
  21. else
  22. {
  23. // Encrypt the section.
  24. section.SectionInformation.ProtectSection(
  25. "DataProtectionConfigurationProvider");
  26. }
  27. // Save the current configuration.
  28. config.Save();
  29.  
  30. Console.WriteLine("Protected={0}",
  31. section.SectionInformation.IsProtected);
  32. }
  33. catch (Exception ex)
  34. {
  35. Console.WriteLine(ex.Message);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement