Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <system.net>
- <mailSettings>
- <smtp from="email@domain.com" deliveryMethod="Network">
- <network clientDomain="www.domain.com" host="smtp.live.com" defaultCredentials="false" port="25" userName=" email@domain.com " password="password" enableSsl="true" />
- </smtp>
- </mailSettings>
- </system.net>
- param(
- [String] $appPath = $(throw "Application exe file path is mandatory"),
- [String] $sectionName = $(throw "Configuration section is mandatory"),
- [String] $dataProtectionProvider = "DataProtectionConfigurationProvider"
- )
- #The System.Configuration assembly must be loaded
- $configurationAssembly = "System.Configuration, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a"
- [void] [Reflection.Assembly]::Load($configurationAssembly)
- Write-Host "Encrypting configuration section..."
- $configuration = [System.Configuration.ConfigurationManager]::OpenExeConfiguration($appPath)
- $section = $configuration.GetSection($sectionName)
- if (-not $section.SectionInformation.IsProtected)
- {
- $section.SectionInformation.ProtectSection($dataProtectionProvider);
- $section.SectionInformation.ForceSave = [System.Boolean]::True;
- $configuration.Save([System.Configuration.ConfigurationSaveMode]::Modified);
- }
- Write-Host "Succeeded!"
- powershell "& ""C:Documents and SettingsVlericPMy DocumentsWindowsPowerShellEncryptAppConfigSection.ps1""" '$(TargetPath)' 'connectionStrings'
- string provider = "RSAProtectedConfigurationProvider";
- string section = "connectionStrings";
- protected void btnEncrypt_Click(object sender, EventArgs e)
- {
- Configuration confg =
- WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
- ConfigurationSection configSect = confg.GetSection(section);
- if (configSect != null)
- {
- configSect.SectionInformation.ProtectSection(provider);
- confg.Save();
- }
- }
- protected void btnDecrypt_Click(object sender, EventArgs e)
- {
- Configuration config =
- WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
- ConfigurationSection configSect = config.GetSection(section);
- if (configSect.SectionInformation.IsProtected)
- {
- configSect.SectionInformation.UnprotectSection();
- config.Save();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement