Is there a utility that will encrypt a named configuration section (or just the connectionStrings
section) in an app.config
file in a similar manne
PowerShell implementation based on MichelZ's answer:
<#
.SYNOPSIS
Encrypts a section in .NET app configuration file.
#>
function Protect-DotNetConfigSection
{
[CmdletBinding()]
param
(
# Path to .exe file.
[Parameter(Mandatory = $true)]
[string] $ExePath,
# List of section names.
[Parameter(Mandatory = $true)]
[string[]] $Sections
)
$config = [System.Configuration.ConfigurationManager]::OpenExeConfiguration($ExePath)
foreach ($section in $Sections)
{
$config.GetSection($section).SectionInformation.ProtectSection('DataProtectionConfigurationProvider')
}
$config.Save()
}
Protect-DotNetConfigSection 'C:\MyApp\MyApp.exe' 'connectionStrings'
Protect-DotNetConfigSection 'C:\MyApp\MyApp.exe' @('connectionStrings', 'appSettings')