【发布时间】:2022-02-19 09:38:12
【问题描述】:
我有以下控制台应用程序代码:
// 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;
}
此代码在 Framework 4.8 上运行良好,但当我在 Core 3.1 上尝试时,它会抛出
PlatformNotSupportedException
在“UNPROTECT”代码处。
这是在同一个工作站上。
ConfigurationManager 和 SectionInformation 的官方文档都显示了与 Core 3.0 和 3.1 的兼容性。
我猜这些类与Core“兼容”是为了方便访问配置文件,但解密不是因为解密的密钥存储在Framework中,而是Core是跨平台的,因此不会有访问密钥。 (是吗?)
如果此平台不支持连接字符串的解密,是否有其他加密/解密连接字符串的首选替代方法?
我高高在上,但似乎找不到任何东西。
注意:解密加密连接字符串的能力是必不可少的!
【问题讨论】:
-
UnprotectSection MS Docs 不显示与 .NET Core 的兼容性,仅显示与 .NET Framework 和 .NET 平台扩展 (docs.microsoft.com/en-us/dotnet/api/…) 的兼容性。我认为您需要查看 Windows 兼容包 (docs.microsoft.com/en-us/dotnet/core/porting/…) 才能安装这些平台扩展。有关 Windows 包的更多信息:stackoverflow.com/questions/53097067/…
标签: c# .net-core connection-string app-config .net-framework-4.8