【发布时间】:2017-06-28 23:44:14
【问题描述】:
我已经在这几天了,看不出我做错了什么。如果有人能告诉我我做错了什么,我将不胜感激。
我经历了多次迭代。这是我目前所拥有的,但不起作用。
Startup.cs
var creds = new StorageCredentials(settings.CloudStorageAccount, settings.CloudStorageKey);
var account = new CloudStorageAccount(creds, true);
var blobClient = account.CreateCloudBlobClient();
var container = blobClient.GetContainerReference($"{dpsFolder}-{_env.EnvironmentName}".ToLower());
container.CreateIfNotExistsAsync().GetAwaiter().GetResult();
services.AddDataProtection()
.SetApplicationName(settings.ApplicationName)
.PersistKeysToAzureBlobStorage(container, dpsFileName);
控制器 ctor
public ExternalSettingController([FromServices] IExternalSettingRepo repo,
[FromServices] IOptions<AppSettings> opts,
[FromServices] ILogger<ExternalSettingController> logger,
[FromServices] IHostingEnvironment env,
[FromServices] IDataProtectionProvider dpp)
: base(opts, repo, logger)
{
_dataProtector = dpp.CreateProtector("blah.Integration");
}
Get 方法中的实际调用
toReturn.Plain = _dataProtector.Unprotect(found.SettingValue);
一切似乎都加载正常,尽我所能通过调试器判断。设置正确。当调用 Unprotect 时,系统选择使用 C:\Users\blah\AppData\Local\ASP.NET\DataProtection-Keys 中的密钥之一,而不是上传到 Azure Blob 存储的密钥。
一点背景,因为它可能会影响事情。我最初创建了一个单独的 DataProtectionService 类,该类使用我为项目维护的密钥使用 IDataProtection 进行加密。它没有安装在 Azure 上一个可读的地方,所以我不得不切换它的存储位置。这就是现在 Azure 存储中的关键。我尝试解密的数据最初是在本地存储相同密钥时加密的。
我做错了什么?
【问题讨论】:
标签: asp.net-core .net-core azure-blob-storage