System.EncryptionUtils.Decrypt C# (CSharp) Method

Decrypt() public static method

Decrypts bytes encrypted with AES 256
public static Decrypt ( this data, byte key ) : byte[]
data this
key byte 256bit key
return byte[]
		public static byte[] Decrypt(this byte[] data, byte[] key)
		{
			if (data == null) throw new ArgumentNullException("data");
			if (key == null || key.Length != 32) throw new ArgumentException("Key must have 32 length", "key");
            
		
			using (var c = Aes.Create())
			{
				c.Key = key;
				using (var ms = new MemoryStream())
				{
					int ReadPos = 0;
					byte[] IV = new byte[c.IV.Length];
					Array.Copy(data, IV, IV.Length);
					c.IV = IV;
					ReadPos += c.IV.Length;
					using (var cs = new CryptoStream(ms, c.CreateDecryptor(), CryptoStreamMode.Write))
					{
						cs.Write(data, ReadPos, data.Length - ReadPos);
						cs.FlushFinalBlock();
					}
					return ms.ToArray();
				}
				
			}
			
		}