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

Problem with usage... #7

Closed CarlCummingsSNB closed 2 years ago

CarlCummingsSNB commented 2 years ago

I am trying to use your product to read an encrypted appsettings.{environment}.json file.

Using the console part I am able to encrypt and decrypt the file fine but in my Program.cs I am not get the key decrypted...

I hope someone will be able to help me

Here is the code I am using the Program.cs

public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }) .ConfigureLogging(logging => { logging.ClearProviders(); logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); }) .ConfigureAppConfiguration((hostingContext, cfg) => { cfg.AddEncryptedAppSettings(hostingContext.HostingEnvironment, crypter => { crypter.CertificateSubjectName = "Hazard Identification Cert - DTI"; crypter.KeysToDecrypt = new List<string> { "ConnectionStrings:HazardExternalData" }; }); }) .UseNLog(); // NLog: Setup NLog for Dependency injection; }

everything compiles fine and the initial page runs fine but when I call the page that makes the connection to my DB it failes because the key is still encrypted..

Edited....(Oct 10) Just a FYI here is the code I am using in my Startup.cs to use the key. services.AddDbContext<HazidExternalData>(options => options.UseOracle(Configuration.GetConnectionString("HazidExternalData")));

CarlCummingsSNB commented 2 years ago

I just found the needle in the hay stack.... And this can be ignored.... It helps if you are trying to decrypt the correct key....