我正在开发 ASP.Net Core Web API,在开发环境中,我们只需在文件中以纯文本形式编写连接字符串appsettings.json。但现在我们要将此 API 发布到我们的生产服务器和 Web(我们将使用 FortiWeb 来发布 API,而不是 Azure),因此我们不能再以纯文本形式提供用户凭据。
我一直在寻找保护/加密连接字符串的方法,但大多数解决方案使用 Azure Key Vault 或用户机密。我决定按照这篇文章来加密和解密appsettings.json信息,但它有点不完整。我设法创建了文章中描述的类,但我陷入困境并且不知道如何使用它。这是我第一次完全从头开始开发 API,而且我在信息安全方面完全是新手。
这是我到目前为止所拥有的:
存档appsettings.json:
{
"ConnectionStrings": {
"MyConnection": "Data Source=MyServerName;Initial Catalog=MyDb;Persist Security Info=True;User ID=MyUser;Password=MyPwd"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
Run Code Online (Sandbox Code Playgroud)
上课时DecryptedConfiguration.cs:
public class DecryptedConfiguration : ConfigurationProvider
{
public ICryptoTransform Decryptor;
private ICryptoTransform Encryptor;
internal DecryptedConfiguration(byte[] Key, byte[] IV)
{
Aes aes = Aes.Create();
Decryptor …Run Code Online (Sandbox Code Playgroud) 我正在使用所有这些平面样式选项开发一个 winforms 应用程序,它使该应用程序看起来很像 Win10 应用程序,所以我想知道是否可以检测操作系统是否正在使用深色模式,因此我可以将颜色调整为适合深色(或浅色)模式。
我发现了一些有关它的问题,但它们与 UWP 和 WPF 有关,因此该解决方案不适用于我的应用程序。