I have the following code for a console application:
// Get the app config file.
var configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Get the sections to unprotect.
ConfigurationSection connStrings = configuration.ConnectionStrings;
string connection = null;
if (connStrings != null)
{
// UNPROTECT
connStrings.SectionInformation.UnprotectSection();
connection = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;
}
This code works just fine on Framework 4.8, but when I try it on Core 3.1, it throws
PlatformNotSupportedException
at the "UNPROTECT" code.
This is on the same work station and everything.
The official documentation for both ConfigurationManager and SectionInformation shows compatibility with Core 3.0 and 3.1.
I'm guessing that the classes are "compatible" with Core for convenience of accessing the config file but the decryption is not because the keys for decryption are stored in the Framework, but Core is cross platform and therefore won't have access to the keys. (Yes?)
If this platform doesn't support decryption of connection strings, is there some preferred alternative to encrypting/decrypting connection strings?
I have looked high and low but don't seem to be able to find anything.
NOTE: The ability to decrypt the encrypted connection string is essential!