I am trying to learn some cryptography - from scratch - an for this I am trying to test the the protect and unprotect-methods which both contain the MachineKey-class.
But when putting the code inside an asp.net console application, I get the following error
"machinekey does not occur in the current context"
, even when trying to include
using System.Web.Security
What am I doing wrong? I just want to test the two methods and therefore place them in a console application, where I can easily check the output.
snippet of the Protect-method:
public static string Protect(string unprotectedText)
{
var unprotectedBytes = Encoding.UTF8.GetBytes(unprotectedText);
var protectedBytes = MachineKey.Protect(unprotectedBytes, "Recipient: user");
var protectedText = Convert.ToBase64String(protectedBytes);
return protectedText;
}
I installed the package Microsoft.AspNetCore.DataProtection.SystemWeb
.