gpt4 book ai didi

c# - 在 azure 上存储和使用现有数据保护 key

转载 作者:行者123 更新时间:2023-12-02 08:32:15 25 4
gpt4 key购买 nike

我正在尝试将 prem key 与 azure 云设置同步,以便两个环境都可以解密授权 header 访问 token 。

目前我有这样的设置:

将此格式的现有 xml key 文件添加到 azure blob 存储中:

<?xml version="1.0" encoding="utf-8"?>
<key id="id..." version="1">
<creationDate>2018-05-08T17:44:54.9313191Z</creationDate>
<activationDate>2018-05-08T17:44:54.8979462Z</activationDate>
<expirationDate>2023-05-07T17:44:54.8979462Z</expirationDate>
<descriptor deserializerType="Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
<descriptor>
<encryption algorithm="AES_256_CBC" />
<validation algorithm="HMACSHA256" />
<masterKey p4:requiresEncryption="true" xmlns:p4="http://schemas.asp.net/2015/03/dataProtection">
<!-- Warning: the key below is in an unencrypted form. -->
<value>my-shared-key</value>
</masterKey>
</descriptor>
</descriptor>
</key>

在应用程序启动期间注册 key ,如下所示:

services.AddDataProtection()
.SetApplicationName("common-app-name")
.DisableAutomaticKeyGeneration()
.PersistKeysToAzureBlobStorage(new Uri("my uri/sas"));

在启动过程中看到这些警告/错误:

warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[15]
Unknown element with name 'creationDate' found in keyring, skipping.
Loaded
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager:Warning: Unknown element with name 'creationDate' found in keyring, skipping.
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager:Warning: Unknown element with name 'activationDate' found in keyring, skipping.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[15]
Unknown element with name 'activationDate' found in keyring, skipping.
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager:Warning: Unknown element with name 'expirationDate' found in keyring, skipping.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[15]
Unknown element with name 'expirationDate' found in keyring, skipping.
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager:Warning: Unknown element with name 'descriptor' found in keyring, skipping.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[15]
Unknown element with name 'descriptor' found in keyring, skipping.

Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider:Error: An error occurred while reading the key ring.

System.InvalidOperationException: The key ring does not contain a valid default protection key. The data protection system cannot create a new key because auto-generation of keys is disabled.
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.CreateCacheableKeyRingCore(DateTimeOffset now, IKey keyJustAdded)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.ICacheableKeyRingProvider.GetCacheableKeyRing(DateTimeOffset now)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRingCore(DateTime utcNow)
fail: Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider[48]
An error occurred while reading the key ring.

我哪里出错了?

提前致谢。

更新:

还尝试了这种注册 azure key 的方法,但仍然看到相同的错误:

var storageAccount = CloudStorageAccount.Parse("<connectionstring + access key>");
var client = storageAccount.CreateCloudBlobClient();

var container = client.GetContainerReference("dev");
container.CreateIfNotExistsAsync().GetAwaiter().GetResult();

services.AddDataProtection()
.SetApplicationName("common-name")
.PersistKeysToAzureBlobStorage(container, "keys.xml")
.DisableAutomaticKeyGeneration();

最佳答案

最终我自己找到了答案,不幸的是,此信息没有记录在任何地方的 MS Azure 文档中。

简单来说,您需要将关键的 xml 元素包装在根 <repository></repository> 中元素。

https://stackoverflow.com/a/57804689/471565

关于c# - 在 azure 上存储和使用现有数据保护 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59855626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com