In this repository you will find the source code of my NuGet package: Fededim.Extensions.Configuration.Protected
Fededim.Extensions.Configuration.Protected is an improved ConfigurationBuilder which allows partial or full encryption of configuration values stored inside any possible ConfigurationSource and fully integrated in the ASP.NET Core architecture. Fededim.Extensions.Configuration.Protected implements a custom ConfigurationBuilder and a custom ConfigurationProvider defining a custom tokenization tag which whenever found inside a configuration value decrypts the enclosed encrypted data using a pluggable encryption/decryption provider (a default one based on ASP.NET Core Data Protection API is provided).
You can find the source code here Fededim.Extensions.Configuration.Protected
Fededim.Extensions.Configuration.Protected.DataProtectionAPI is the standard Microsoft Data Protection API encryption/decryption provider for Fededim.Extensions.Configuration.Protected
You can find the source code here Fededim.Extensions.Configuration.Protected.DataProtectionAPI
You can find a detailed article on my personal homepage explaning the origin, how to use it and the main point of the implementation.
This a xUnit test project which tests thoroughly the two above packages in order to improve the reliability and the code quality.
It creates sample data for all ConfigurationSources provided by Microsoft .NET (a JSON file, a XML file, environment variables, an in-memory dictionary and command line arguments) containing a 2*fixed set of entries (100000, except for environment variables limited up to 2000 for technical reasons), one in plaintext with random datatype and value, and another with the same value but encrypted. Arrays are generated with a random number of elements, while XML and JSON files are generated in addition with a random number of hierarchical levels, consisting of an approximate size from 60 MB up to 100 MB each.
It loads then the sample data with ProtectedConfigurationBuilder in order to decrypt it and tests that all plaintext values are the same as those that have been decrypted. For example a test case on the JsonConfigurationProvider generated a plain-text file with a total size of 60MB and an encrypted file with a total size of 91MB, the test has ended in around 10 seconds for generating the random JSON file, encrypting it, decrypting it using the ProtectedConfigurationBuilder, and checking that every decrypted key was equal to the plaintext one.
Moreover all the whole set of five test cases was repeated for 1000 iterations (Test Explorer --> Run Until Failure in Visual Studio, unluckily it is not available for multi target tests, so I had to execute each of them separately for each supported framework). On net48 it run for a total time 3318 minutes, on net10.0 for a total time of 2336 minutes, without raising any error as you can see in the pictures below (the full set of test trace file are downloadble as zip archive).
Net472 Endurance Test Endurance test trace files
Coming soon
Net48 Endurance Test Endurance test trace files

Net8.0 Endurance Test Endurance test trace files

Net10.0 Endurance Test Endurance test trace files

Fededim.Extensions.Configuration.ProtectedJson (OBSOLETE PLEASE USE Fededim.Extensions.Configuration.Protected.DataProtectionAPI)
Fededim.Extensions.Configuration.ProtectedJson is my first package and it is an improved JSON configuration provider which allows partial or full encryption of configuration values stored in appsettings.json files and fully integrated in the ASP.NET Core architecture. Basically, it implements a custom ConfigurationSource and a custom ConfigurationProvider defining a custom tokenization tag which whenever found decrypts the enclosed encrypted data using ASP.NET Core Data Protection API.
You can find the source code here Fededim.Extensions.Configuration.ProtectedJson but this package has become however obsolete in favour of the more versatile Fededim.Extensions.Configuration.Protected.DataProtectionAPI.
You can find a detailed article on my personal homepage explaning the origin, how to use it and the main point of the implementation.