public static byte[] Decode (string encodedData, MachineKeyProtection protectionOption)
{
if (encodedData == null)
throw new ArgumentNullException ("encodedData");
int dlen = encodedData.Length;
if (dlen == 0 || dlen % 2 == 1)
throw new ArgumentException ("encodedData");
byte[] data = MachineKeySectionUtils.GetBytes (encodedData, dlen);
if (data == null || data.Length == 0)
throw new ArgumentException ("encodedData");
var config = WebConfigurationManager.GetWebApplicationSection ("system.web/machineKey") as MachineKeySection;
byte[] result = null;
Exception ex = null;
try {
switch (protectionOption) {
case MachineKeyProtection.All:
result = MachineKeySectionUtils.VerifyDecrypt (config, data);
break;
case MachineKeyProtection.Encryption:
result = MachineKeySectionUtils.Decrypt (config, data);
break;
case MachineKeyProtection.Validation:
result = MachineKeySectionUtils.Verify (config, data);
break;
default:
return MachineKeySectionUtils.GetBytes (encodedData, dlen);
}
} catch (Exception e) {
ex = e;
}
if (result == null || ex != null)
throw new HttpException ("Unable to verify passed data.", ex);
return result;
}