Encrypting custom configuration settings

397 Views Asked by At

I'm having some troubles encrypting a configuration section. We use a package from an external supplier and the web.config is structured in the following way:

web.config

<appSettings file="customSettings.config">
  <add key="generic_setting" value="true"/>
  <add key="another_generic_setting" value="false"/>
</appSettings>

customSettings.config

<appSettings>
  <add key="company_db_username" value="sa"/>
  <add key="company_db_password" value="secret"/>
</appSettings>

We use WiX to create an installation package (msi) so we can deploy this in our organization. One custom action we execute is the encryption of the appSettings section. In the situation depicted above it unfortunately only encrypts the section in the web.config file and leaves the customSettings.config untouched.

I did notice that the configSource attribute works a bit better with encryption than the file attribute, but it doesn't support merging elements from both files. Now I could programmatically merge the elements of the customSettings.config into web.config before I encrypt everything in the custom action, but I was wondering if there is a cleaner solution to this.

1

There are 1 best solutions below

1
On

Based on your example, where the information you're encrypting is a DB username and password, one alternative is to use Windows Authentication to connect to your DB the first time. The initial user would have very restricted rights.

Use that connection to obtain the credentials / connection string for a higher-privilege account, which you have previously stored using item-level DB encryption (see OPEN SYMMETRIC KEY and ENCRYPTBYKEY).