Skip to content

Instantly share code, notes, and snippets.

@phillipsj
Created October 8, 2015 00:52
Show Gist options
  • Save phillipsj/aa374e21ab5bc9b0ea54 to your computer and use it in GitHub Desktop.
Save phillipsj/aa374e21ab5bc9b0ea54 to your computer and use it in GitHub Desktop.
MachineKeyDataProtector Implementation from StackOverflow
public class MachineKeyProtectionProvider : IDataProtectionProvider
{
public IDataProtector Create(params string[] purposes)
{
return new MachineKeyDataProtector(purposes);
}
}
public class MachineKeyDataProtector : IDataProtector
{
private readonly string[] _purposes;
public MachineKeyDataProtector(string[] purposes)
{
_purposes = purposes;
}
public byte[] Protect(byte[] userData)
{
return MachineKey.Protect(userData, _purposes);
}
public byte[] Unprotect(byte[] protectedData)
{
return MachineKey.Unprotect(protectedData, _purposes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment