示例#1
0
 private static byte[] DecryptAes128CbcWithGzip(byte[] data, byte[] key)
 {
     byte[] gzippedFile;
     using (var cipher = new AesManaged { Mode = CipherMode.CBC, Key = key })
         gzippedFile = cipher.CreateDecryptor().TransformFinalBlock(data, 0, data.Length).Skip(16).ToArray();
     using (var inStream = new MemoryStream(gzippedFile))
     using (var zipStream = new DeflateStream(inStream, CompressionMode.Decompress))
     using (var outStream = new MemoryStream())
     {
         zipStream.CopyTo(outStream);
         return outStream.ToArray();
     }
 }
        /// <summary>
        /// Decode the content
        /// </summary>
        /// <param name="data">Content to decode</param>
        /// <returns>Decoded content</returns>
        public byte[] Decode(byte[] data)
        {
            var output = new MemoryStream ();
            var input = new MemoryStream (data);
            /*
            using (var stream = new System.IO.Compression.DeflateStream (input, System.IO.Compression.CompressionMode.Decompress))
                stream.CopyTo (output);
            return output.ToArray ();
            */

            using (var stream = new DeflateStream (input, CompressionMode.Decompress))
                stream.CopyTo (output);
            return output.ToArray ();
        }
		public static void DecompressTileBlock(byte[] buffer, int bufferStart, int bufferLength)
		{
			using (MemoryStream memoryStream = new MemoryStream())
			{
				memoryStream.Write(buffer, bufferStart, bufferLength);
				memoryStream.Position = 0L;
				bool flag = memoryStream.ReadByte() != 0;
				MemoryStream memoryStream3;
				if (flag)
				{
					MemoryStream memoryStream2 = new MemoryStream();
					using (DeflateStream deflateStream = new DeflateStream((Stream)memoryStream, CompressionMode.Decompress, CompressionLevel.BestCompression))
					{
						deflateStream.CopyTo(memoryStream2);
						deflateStream.Close();
					}
					memoryStream3 = memoryStream2;
					memoryStream3.Position = 0L;
				}
				else
				{
					memoryStream3 = memoryStream;
					memoryStream3.Position = 1L;
				}
				using (BinaryReader binaryReader = new BinaryReader(memoryStream3))
				{
					int xStart = binaryReader.ReadInt32();
					int yStart = binaryReader.ReadInt32();
					short width = binaryReader.ReadInt16();
					short height = binaryReader.ReadInt16();
					NetMessage.DecompressTileBlock_Inner(binaryReader, xStart, yStart, (int)width, (int)height);
				}
			}
		}
示例#4
0
        private static byte[] Decompress(byte[] data)
        {
            // While a "real" PNG uses Zlib for the image data, the CgBI PNG image data is compressed with Deflate.
            using (var inputStream = new MemoryStream(data, false))
            {
                using (var deflateStream = new DeflateStream(inputStream, CompressionMode.Decompress))
                {
                    using (var newData = new MemoryStream())
                    {
                        deflateStream.CopyTo(newData);
                        return newData.ToArray();
                    }
                }

            }
        }