In my .NET 5 Blazor Server Application I add dataprotection to my services using the following line in my Program.cs
builder.Services.AddDataProtection()
.SetApplicationName("WhateverApplicationName")
.PersistKeysToDbContext<KpaContext>();
Now when I try to get data from ProtectedLocalStorage using this code
try
{
var sessionid = await ProtectedLocalStorage.GetAsync<Guid>("BrowserId");
}
catch(Exception ex)
{
Debugger.Break();
}
It keeps throwing this error:
System.Security.Cryptography.CryptographicException: The payload was invalid.
at Microsoft.AspNetCore.DataProtection.Managed.ManagedAuthenticatedEncryptor.Decrypt(ArraySegment
1 protectedPayload, ArraySegment1 additionalAuthenticatedData) at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status) at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData) at Microsoft.AspNetCore.DataProtection.DataProtectionCommonExtensions.Unprotect(IDataProtector protector, String protectedData) at Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage.ProtectedBrowserStorage.GetAsync[TValue](String purpose, String key)
The application runs on a docker container.
The table DataProtectionKeys contains a record of a key which is valid from 05-07 till 03-10 so the key should be active.
What am I doing wrong. I used this link to configure data protection: