Westwind.ApplicationConfiguration icon indicating copy to clipboard operation
Westwind.ApplicationConfiguration copied to clipboard

Nested lists encryption

Open JstrzAtW2M opened this issue 9 years ago • 1 comments

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?

JstrzAtW2M avatar Jun 25 '15 14:06 JstrzAtW2M

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.

RickStrahl avatar Jun 26 '15 07:06 RickStrahl