I want to encrypt the connection string in appsetings.json and decrypt before passing it to options.UseSqlServer(Configuration["Database:Connection"])) in ConfigureServices method. Unfortunately there is not much about this on internet about asp.net core. The connection string looks like the following:
"Database": {
"Connection": "string"
}
I might also like to so the same with other setting objects, following is so far I have gone by looking around but I guess I am lost. Any recommendations, highly appreciated. Thank you.
public class CustomConfigProvider : ConfigurationProvider, IConfigurationSource
{
public CustomConfigProvider()
{
}
public override void Load()
{
Data = UnencryptMyConfiguration();
}
private IDictionary<string, string> UnencryptMyConfiguration()
{
// do whatever you need to do here, for example load the file and unencrypt key by key
//Like:
var configValues = new Dictionary<string, string>
{
{"Database", "string"}
};
return configValues;
}
private IDictionary<string, string> CreateAndSaveDefaultValues(IDictionary<string, string> defaultDictionary)
{
var configValues = new Dictionary<string, string>
{
{"Database", "string"},
};
return configValues;
}
public IConfigurationProvider Build(IConfigurationBuilder builder)
{
return new CustomConfigProvider();
}
}