devattic / ConfigCrypter

DevAttic ConfigCrypter is a library that lets you encrypt configuration files and decrypt them on the fly in .NET Core applications.
MIT License
48 stars 18 forks source link

More than one key in config file #3

Closed stuturkington closed 2 years ago

stuturkington commented 3 years ago

Nice project!

I encrypted 2 keys in my appsettings.

I think now it has to do with the JSON. Encrypt and decrypt work in the console program using: key Serilog.WriteTo[2].Args.connectionString. When I try and decrypt it on the fly it says key not found (i've also used : to separate the key values. Is there a way to list the keys in the Dictionary?

System.Collections.Generic.KeyNotFoundException: The given key 'Serilog.WriteTo[2].Args.connectionString' was not present in the dictionary.

mrukas commented 3 years ago

Hi! Lets say you have the following key in your appsettings:

  "Nested": {
    "KeyToEncrypt": "encrypted1",
    "ListOfValue": [
      "value1",
      "encyptedValue2"
    ]
  }

If you now want to decrypt the second entry in the ListOfValue array you need to specify it in the KeysToDecrypt list like this: Nested:ListOfValue:1.

This should work.