Exemplo n.º 1
0
 private static byte[] preprocess(byte[] bytes, MemoryStream memoryStream, NetWebClient.Encoding encoding, bool encrypt)
 {
     NetWebClient.clearStream(memoryStream);
     if (encoding != NetWebClient.Encoding.Deflate)
     {
         if (encoding != NetWebClient.Encoding.GZip)
         {
             memoryStream.Write(bytes, 0, bytes.Length);
         }
         else
         {
             using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Compress, true))
             {
                 gzipStream.Write(bytes, 0, bytes.Length);
             }
         }
     }
     else
     {
         uint num = NetWebClient.calcAdler32(bytes.LongLength, bytes);
         memoryStream.WriteByte(120);
         memoryStream.WriteByte(156);
         if (bytes.Length <= 128)
         {
             NetWebClient.deflateRawBlock(memoryStream, bytes, 0, bytes.Length);
         }
         else
         {
             using (DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionMode.Compress, true))
             {
                 deflateStream.Write(bytes, 0, bytes.Length);
             }
         }
         memoryStream.WriteByte((byte)(num >> 24 & 255U));
         memoryStream.WriteByte((byte)(num >> 16 & 255U));
         memoryStream.WriteByte((byte)(num >> 8 & 255U));
         memoryStream.WriteByte((byte)(num >> 0 & 255U));
     }
     if (encrypt)
     {
         memoryStream.Position = 0L;
         int num2 = (int)memoryStream.Length;
         int num3 = Cryptography.calcEncryptedSize(num2);
         NetWebClient.shared_.resizeTemporary(num3);
         byte[] tmp_ = NetWebClient.shared_.tmp_;
         memoryStream.Read(tmp_, 0, num3);
         Cryptography.padding(num2, tmp_);
         bytes = new byte[num3];
         Cryptography.Instance.encrypt(num3, bytes, num3, tmp_);
     }
     else
     {
         bytes = memoryStream.ToArray();
     }
     return(bytes);
 }
Exemplo n.º 2
0
        private static bool checkHash(Stream received, MemoryStream decompressed)
        {
            if (received.Length < 4L)
            {
                return(false);
            }
            received.Seek(-4L, SeekOrigin.End);
            uint num = (uint)((uint)((byte)received.ReadByte()) << 24);

            num |= (uint)((uint)((byte)received.ReadByte()) << 16);
            num |= (uint)((uint)((byte)received.ReadByte()) << 8);
            num |= (uint)((uint)((byte)received.ReadByte()) << 0);
            uint num2 = NetWebClient.calcAdler32(decompressed);

            return(num2 == num);
        }