Closed planyway closed 1 year ago
EFCore model is cached when you access it the first time for performance reasons. But there is a way to that allows you to have "multiple" models at the same time, checkout this article: https://docs.microsoft.com/en-us/ef/core/modeling/dynamic-model
Everytime a user read/edit the database, he/she has to type a key he/she originally used to encrypt data. This typed key is going to overwrite appsettings.json's key, so ApplicationDbContext will use this typed key to encrypt/decrypt the data.
I can now get user's key from the razor page, and assign the key to HomeController's configuration (private readonly IConfiguration configuration) by using Httppost. Now I wonder how I can force ApplicationDbContext to re-decrypt the data it has, after the user enters a key? Because before the user enters the key, ApplicationDbContext should only managed to get garbled text or something weird, because the appsettings.json key must be a wrong key.
All I see now here are codes that only configure the AES key before the model is created, so I am finding a way to let the key reconfigure after the model is created.