daily pastebin goal
15%
SHARE
TWEET

Untitled

a guest Jan 20th, 2017 119 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <system.net>
  2.   <mailSettings>
  3.    <smtp from="email@domain.com" deliveryMethod="Network">
  4.     <network clientDomain="www.domain.com" host="smtp.live.com" defaultCredentials="false" port="25" userName=" email@domain.com " password="password" enableSsl="true" />
  5.    </smtp>
  6.   </mailSettings>
  7.  </system.net>
  8.    
  9. param(
  10.   [String] $appPath = $(throw "Application exe file path is mandatory"),
  11.   [String] $sectionName = $(throw "Configuration section is mandatory"),
  12.   [String] $dataProtectionProvider = "DataProtectionConfigurationProvider"
  13. )
  14.  
  15. #The System.Configuration assembly must be loaded
  16. $configurationAssembly = "System.Configuration, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a"
  17. [void] [Reflection.Assembly]::Load($configurationAssembly)
  18.  
  19. Write-Host "Encrypting configuration section..."
  20.  
  21. $configuration = [System.Configuration.ConfigurationManager]::OpenExeConfiguration($appPath)
  22. $section = $configuration.GetSection($sectionName)
  23.  
  24. if (-not $section.SectionInformation.IsProtected)
  25. {
  26.   $section.SectionInformation.ProtectSection($dataProtectionProvider);
  27.   $section.SectionInformation.ForceSave = [System.Boolean]::True;
  28.   $configuration.Save([System.Configuration.ConfigurationSaveMode]::Modified);
  29. }
  30.  
  31. Write-Host "Succeeded!"
  32.    
  33. powershell "& ""C:Documents and SettingsVlericPMy DocumentsWindowsPowerShellEncryptAppConfigSection.ps1""" '$(TargetPath)' 'connectionStrings'
  34.    
  35. string provider = "RSAProtectedConfigurationProvider";
  36.  
  37.  
  38. string section = "connectionStrings";  
  39.  
  40. protected void btnEncrypt_Click(object sender, EventArgs e)  
  41.  
  42. {
  43.  
  44.    Configuration confg =
  45.    WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
  46.  
  47.    ConfigurationSection configSect = confg.GetSection(section);
  48.  
  49.    if (configSect != null)
  50.  
  51.    {
  52.       configSect.SectionInformation.ProtectSection(provider);
  53.       confg.Save();
  54.  
  55.    }
  56.  
  57. }
  58. protected void btnDecrypt_Click(object sender, EventArgs e)
  59. {
  60.     Configuration config =
  61.         WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
  62.     ConfigurationSection configSect = config.GetSection(section);
  63.     if (configSect.SectionInformation.IsProtected)
  64.     {
  65.         configSect.SectionInformation.UnprotectSection();
  66.         config.Save();
  67.     }
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top