views:

47

answers:

1

I would like to protect one key/value pair in my appSettings but not the others using something like I've previously done with the ProtectSection method as seen below.

var configurationSection = config.GetSection("appSettings");
configurationSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");

Ideally I would like to do something like the following:

var configurationElement = config.GetSection("appSettings").GetElement("Protected");
configurationElement.ElementInformation.ProtectElement("DataProtectionConfigurationProvider");

Here is the example appSettings I would be operating on:

<configuration>
<appSettings>
    <add key="Unprotected" value="ChangeMeFreely" />
    <add key="Protected" value="########"/>
</appSettings>
</configuration>

I've been searching but haven't found a way to do this. Is this possible?

+2  A: 

Not out of the box - .NET offers you the ability to encrypt sections - but not individual elements. However, since those are only strings, it's absolutely possible for you yourself to create some scheme to encrypt the string before saving it to file, and decrypt it after it's been read from the config file.

But this won't be transparent - you'll have to do it yourself and you have to do it explicitly.

marc_s