RickStrahl / Westwind.ApplicationConfiguration

Strongly typed, code-first configuration classes for .NET applications
http://west-wind.com/westwind.applicationconfiguration/
178 stars 36 forks source link

Nested lists encryption #15

Open JstrzAtW2M opened 9 years ago

JstrzAtW2M commented 9 years ago

I've read the previous post about this and I've tried various methods but I keep getting an error.

My config class is like this

public class ClientConfiguration : Westwind.Utilities.Configuration.AppConfiguration
{
    private StoreConfiguration[] _Stores;

    public StoreConfiguration[] Stores
    {
        get
        {
            return this._Stores;
        }
        set
        {
            this._Stores = value;
        }

    }
  }

My AppConfig class calls this

   static AppConfig()
    {
        XmlFileConfigurationProvider<ClientConfiguration> provider
            = new XmlFileConfigurationProvider<ClientConfiguration>();

        provider.XmlConfigurationFile = AppUtility.GetAppRootPath() + @"\Config\config.xml";
        provider.EncryptionKey = "MyKey";
        provider.PropertiesToEncrypt = "Stores.Password";

        ClientConfiguration = new ClientConfiguration();
        ClientConfiguration.Initialize(provider);
    }

And I keep getting an error 'Invalid encryption property name: stores.password'

Is this possible or am I just adding the property incorrectly?

RickStrahl commented 9 years ago

I don't think you're defining your configuration properly. Nested properties work only with child properties on child objects, not arrays/collections.

In your case Create a class that describes your child object, then attach that to the Stores property. But it won't work with any list data. I'm guessing you actually want a dynamic list, but that does not work. Encryption only work typed properties the top level object or child properties, not child elements in an array/list.