System.Web.Security.MachineKey.Unprotect C# (CSharp) Method

Unprotect() public static method

public static Unprotect ( byte protectedData ) : byte[]
protectedData byte
return byte[]
		public static byte[] Unprotect (byte[] protectedData, params string[] purposes)
		{
			if (protectedData == null)
				throw new ArgumentNullException ("protectedData");

			foreach (var purpose in purposes) {
				if (string.IsNullOrWhiteSpace (purpose))
					throw new ArgumentException ("all purpose parameters must contain text");
			}

			var config = WebConfigurationManager.GetWebApplicationSection ("system.web/machineKey") as MachineKeySection;
			var purposeJoined = string.Join (";", purposes);
			var purposeBytes = GetHashed (purposeJoined);
			var unprotected = MachineKeySectionUtils.Decrypt (config, protectedData);

			for (int i = 0; i < purposeBytes.Length; i++) {
				if (purposeBytes [i] != unprotected [i])
					throw new CryptographicException ();
			}

			var dataLength = unprotected.Length - purposeBytes.Length;
			var result = new byte [dataLength];
			Array.Copy (unprotected, purposeBytes.Length, result, 0, dataLength);
			return result;
		}