【问题标题】:ASP.Net Core Data Protection API in Azure Web AppAzure Web App 中的 ASP.Net Core 数据保护 API
【发布时间】:2017-08-03 04:06:24
【问题描述】:

我正在尝试在我的 Azure Web 应用程序中设置数据保护,因此当我在暂存和生产之间切换时,它不会让所有人退出。我坚持使用 Azure 中的自签名证书加密密钥。

我的问题与以下内容非常相关: ASP.Net Core Data Protection API in a Clustered Environment 但是,这个问题的答案对我不起作用,因为我已经走到了这一步。


当我在本地运行它并在我的机器上安装证书时,我的代码工作得非常好,但是当我部署到我的 Azure Web 应用程序时,它不会启动并且只会引发一般错误:

Unhandled Exception: System.Security.Cryptography.CryptographicException: Exception of type 'System.Security.Cryptography.CryptographicException' was thrown.

为了设置我的数据保护,我在 ConfigureServices 中使用以下代码:

// Add data protection
var storageAccount = CloudStorageAccount.Parse(Configuration["BlobStorage:ConnectionString"]);
var client = storageAccount.CreateCloudBlobClient();
var container = client.GetContainerReference(Configuration["DataProtection:ContainerName"]);
container.CreateIfNotExistsAsync().Wait();

services.AddDataProtection()
    .SetApplicationName(Configuration["DataProtection:ApplicationName"])
    .PersistKeysToAzureBlobStorage(container, Configuration["DataProtection:BlobName"]);
    .ProtectKeysWithDpapiNG($"CERTIFICATE=HashId:{Configuration["Authentication:SingingCertThumbprint"]}",
        DpapiNGProtectionDescriptorFlags.None);

我使用的证书是自签名的,我已通过网络应用程序上的 SSL 证书部分将其上传到 Azure(但是,正如其他帖子中所建议的,我也尝试了受信任的证书 - 不走运)。

我在我的 Azure Web 应用程序中使用 WEBSITE_LOAD_CERTIFICATES 应用程序设置,所以这也不是问题。

另外值得注意的是,如果我删除了

.ProtectKeysWithDpapiNG($"CERTIFICATE=HashId:{Configuration["Authentication:SingingCertThumbprint"]}",
    DpapiNGProtectionDescriptorFlags.None);

然后网络应用程序将启动并正常运行。 但现在我的密钥显然是未加密存储的。

任何帮助将不胜感激,谢谢。

【问题讨论】:

    标签: c# asp.net azure ssl data-protection


    【解决方案1】:

    我也遇到了同样的问题。我尝试将平台更改为 64 位并扩大我的应用计划,但这些都不起作用。 Azure Web App 可能不支持 ProtectKeysWithDpapiNG。我建议您改用 ProtectKeysWithDpapi。密钥将由 Windows DPAPI 加密。

    【讨论】:

    • 感谢您的回复。听到我不是唯一一个遇到这个问题的人,这让我稍微高兴了一点。我尝试了 ProtectKeysWithDpapi 并且可以确认它有效。但是,我需要多个服务器来查看这些数据。所以这对我来说并不是一个真正的解决方案(因此我想使用证书)。
    • 我建议您在 Azure 反馈网站上发布此问题。 feedback.azure.com
    • 甚至ProtectKeysWithDpapi 似乎对我不起作用。它仍然有加密错误
    猜你喜欢
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 2021-06-28
    • 2020-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多