| West Wind Application Settings for .NET |
| Encrypting specific Configuration Keys |
To implement this functionality you can implement a custom constructor on the class:
public WebStoreConfig() { this.SetEnryption("ConnectionString,MailPassword,MerchantPassword","WebStorePassword"); this.ReadKeysFromConfig(); }
Note the call back to the base(false) to force the base constructor to be called. The false value instructs the base class not to call the ReadKeysFromConfig() method automatically, so we have a chance to call the SetEncryption() method.
Alternately you can use those lines in code as well:
WebStoreConfig Config = new WebStoreConfig(); Config.SetEnryption("ConnectionString,MailPassword,MerchantPassword","WebStorePassword"); Config.ReadKeysFromConfig();
The first parameter of SetEncryption is a comma-delimited list of fields in the current class that you want to encrypt. The second parameter is a 'key' that is used in the encryption routine which uses DES encryption to create a symetrical encrypted value.
public WebStoreConfig() { this.SetEncryption("ConnectionString,MailPassword,MerchantPassword","WebStorePassword"); }
Then call
This solution is a prevention mechanism for casual discovery by just browsing the config file. Unless the architecture of the application is known discovering the key or using the class to read the data is not very likely.