-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Tool to give security to the configurations of an ASPNET Core application by encrypting sensitive information and handling in a secure way
· Versions 2.x.x
- NET Core 2.2 and above
This tool allows to encrypt configuration sections on app.settings files, and decrypt the information in runtime adding those configuration as a singleton inside the application.
-
Install ChustaSoft.Tools.SecureConfig package via NuGet Package manager
-
Setup a custom private key in a secure way, ie: as a environment variable. It will be use for encryp/decrypt functionality
-
Create a Settings object inside the project, should match the section that will be encrypted
-
Add the Settings in all the different environment appsettings
-
In Program, add the following line during IWebHost building (through IWebHostBuilder)
- .EncryptSettings<[TSettings]>(true)
- [TSettings] correponds to the settings DTO created in the step 2
- true if you want to encrypt the settings
- false if you want to decrypt the files
- .EncryptSettings<[TSettings]>(true)
-
In Startup, on ConfigureServices, add the following line in order to setup the singleton and manage the encrypted/decrypted settings:
- services.SetUpSecureConfig<[TSettings]>(Configuration, testApikey);
- [TSettings] correpond to the settings DTO created in the step 2
- testApikey corresponds to the secret key created in step 1
- services.SetUpSecureConfig<[TSettings]>(Configuration, testApikey);
-
Inject the settings class object in the class that the project will need, SecureConfig manage this class as a Singleton in the application lifecycle
Full example:
Configuration video tutorial:
That's all!
Enjoy it and do not hesitate to contribute with us.
Follow us on Twitter: