C#C
C#3w ago
46 replies
ImEr1c_

Data protection - help please

Hello! So im making an app and i store user credentials (token) on device and so i would like it to be protected in some way. I see that the most common package would be aspnetcore.dataprotection and so i tried using it. I already use DI so i just added .AddDataProtection() and set the app name and persist file on filesystem, set the directory. And then i made a class that has a contructor argument of IDataProtectionProvider. The problem is that

var prot = provider.CreateProtector("test");
var test = "testt";
var enc = prot.Protect(test);
Console.WriteLine(prot.Unprotect(enc));


(Used for testing as it previously crashed in another scenario but also in this simple one)

And at the last line, the app crashes with
 System.Security.Cryptography.CryptographicException: The payload was invalid. For more information go to https://aka.ms/aspnet/dataprotectionwarning 
Was this page helpful?