public static string Encode (byte[] data, MachineKeyProtection protectionOption)
{
if (data == null)
throw new ArgumentNullException ("data");
var config = WebConfigurationManager.GetWebApplicationSection ("system.web/machineKey") as MachineKeySection;
byte[] result;
switch (protectionOption) {
case MachineKeyProtection.All:
result = MachineKeySectionUtils.EncryptSign (config, data);
break;
case MachineKeyProtection.Encryption:
result = MachineKeySectionUtils.Encrypt (config, data);
break;
case MachineKeyProtection.Validation:
result = MachineKeySectionUtils.Sign (config, data);
break;
default:
return String.Empty;
}
return MachineKeySectionUtils.GetHexString (result);
}