asp.net - DataProtection API (C#) 的问题
问题描述
我有一个带有多个部署槽的 Azure WebApp。我希望每个部署槽都有自己的数据保护密钥。密钥应该在部署之间保持不变。
Uri storageUri = new Uri(blobStorageSasUri);
CloudBlobClient blobClient = new CloudBlobClient(storageUri);
CloudBlobContainer container = blobClient.GetContainerReference("identityserver4dataprotectionkeys");
container.CreateIfNotExistsAsync().GetAwaiter().GetResult();
services.AddDataProtection()
.SetApplicationName($"{_env.EnvironmentName}_identityserver4")
.PersistKeysToAzureBlobStorage(container, $"{_env.EnvironmentName}/dataprotectionkeys.xml");
奇怪的是,应用程序会搜索 Blob 存储中存在的其他键。例如这个例外:
CryptographicException: The key {3c2e44fa-dbeb-4547-8d1d-40f5eed15590} was not found in the key ring.
在 blob 存储中,我有密钥 ID:6bed1559-9bf7-42af-83fd-85fb417c4edc。
此外,blob 存储始终只有一个键。
我在实现这个 API 时遇到了真正的麻烦。非常感谢帮助!
解决方案
我通过使用 keyvault 解决了这个问题。
public void ConfigureServices(IServiceCollection services)
{
services.AddDataProtection()
.PersistKeysToAzureBlobStorage(new Uri("<blobUriWithSasToken>"))
.ProtectKeysWithAzureKeyVault("<keyIdentifier>", "<clientId>", "<clientSecret>");
}
推荐阅读
- swift - 快速获取多个值
- python - 用值注释 matplotlib 子图
- python - Pandas groupby 并计算每月平均值,但在单独的列中显示月份值
- message - 无法访问任何逻辑中的消息发件人
- java - 使用 Springboot 和 feign 客户端进行休息调用时获取选择性字段作为响应
- reactjs - 无需单击按钮即可提交反应表单 - React Bootstrap
- c# - 一个方法返回一个元组,如何在C#中分配两个取元组结果的变量
- c# - 什么时候使用#pragma 校验和?
- javascript - django-dynamic-formset 在错误的位置显示“添加”和“删除”按钮
- python - 单击按钮时如何清除 tkinter 标签显示