Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encrypting custom configuration settings

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.

like image 345
basvo Avatar asked Mar 13 '26 13:03

basvo


1 Answers

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).

like image 197
RickNZ Avatar answered Mar 15 '26 06:03

RickNZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!