ASP.NET Core DataProtection + Redis + 每台机器多个密钥

ASP.NET Core DataProtection + Redis + Multiple Keys per Machine

我正在配置将部署到场中的 .NETCore 项目。我遵循了添加 DataProction 的所有建议,所以我的代码是这样的:

services.AddMvc(
            options =>
                {
                    options.Filters.Add(typeof(AuditAttribute));
                    options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
                    options.AddStringTrimmingProvider();
                }); 
var redis = StackExchange.Redis.ConnectionMultiplexer.Connect(Configuration.GetValue<string>("MySuperApp:RedisConnectionString"));
            services.AddDataProtection()
                .SetApplicationName("MySuperApp")
                .ProtectKeysWithDpapi(true)
                .PersistKeysToRedis(redis, "DataProtection-Keys");

在开发中,我们只有一台服务器运行良好。我们在 Redis 中只有一个条目,例如:

但是当我们去测试时,我们有两个服务器,我们有以下内容:

另外我们邮箱出现如下错误

Exception Type: System.Security.Cryptography.CryptographicException
Exception Message: Error occurred during a cryptographic operation.
Stack Trace: at Microsoft.AspNetCore.DataProtection.Cng.DpapiSecretSerializerHelper.UnprotectWithDpapiCore(Byte* pbProtectedData, UInt32 cbProtectedData, Byte* pbOptionalEntropy, UInt32 cbOptionalEntropy)
at Microsoft.AspNetCore.DataProtection.Cng.DpapiSecretSerializerHelper.UnprotectWithDpapi(Byte[] protectedSecret)
at Microsoft.AspNetCore.DataProtection.XmlEncryption.DpapiXmlDecryptor.Decrypt(XElement encryptedElement)
at Microsoft.AspNetCore.DataProtection.XmlEncryption.XmlEncryptionExtensions.DecryptElement(XElement element, IActivator activator)
at Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.IInternalXmlKeyManager.DeserializeDescriptorFromKeyElement(XElement keyElement)
Additional Info: An exception occurred while processing the key element ''.

有人可以帮我解决这个问题吗?我们是否缺少服务器上的某些配置?

在这里,如果我们删除选项:.ProtectKeysWithDpapi(true) 将正常工作,所有服务器都使用相同的密钥。