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

Protect() public static method

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

			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 bytes = new byte [userData.Length + purposeBytes.Length];
			purposeBytes.CopyTo (bytes, 0);
			userData.CopyTo (bytes, purposeBytes.Length);
			return MachineKeySectionUtils.Encrypt (config, bytes);
		}