Beispiel #1
0
        public void Verify()
        {
            Verify(HeaderFields.MasterSeed, 32,
                   "The length of the master key seed is invalid!");

            Verify(HeaderFields.TransformSeed, 32,
                   "The length of the transform seed is invalid!");

            Verify(HeaderFields.EncryptionIV, 16,
                   "The length of the encryption IV is invalid!");

            Verify(HeaderFields.StreamStartBytes, 32,
                   "The length of the stream start bytes is invalid!");

            var data = Verify(HeaderFields.CipherID, 16,
                              "The length of the cipher engine ID is invalid!");

            if (!BufferEx.Equals(_easEngineId, data))
            {
                throw new FormatException(
                          "Only AES encryption is supported!");
            }

            data = Verify(HeaderFields.CompressionFlags, 4,
                          "The length of compression format is invalid!");

            var compression = (Compressions)
                              BitConverter.ToChar(data, 0);

            if (compression > Compressions.GZip)
            {
                throw new FormatException(
                          "Only no compression and GZip compression are supported!");
            }
        }
Beispiel #2
0
        private bool ReadHashedBlock()
        {
            if (_eof)
            {
                return(false);
            }

            _position = 0;

            if (_reader.ReadUInt32() != _bufferIndex)
            {
                throw new InvalidDataException();
            }

            _bufferIndex++;

            var actualHash = _reader.ReadBytes(32);

            if ((actualHash == null) || (actualHash.Length != 32))
            {
                throw new InvalidDataException();
            }

            var bufferSize = _reader.ReadInt32();

            if (bufferSize < 0)
            {
                throw new InvalidDataException();
            }

            if (bufferSize == 0)
            {
                if (actualHash.Any(x => x != 0))
                {
                    throw new InvalidDataException();
                }

                _eof    = true;
                _buffer = new byte[0];

                return(false);
            }

            _buffer = _reader.ReadBytes(bufferSize);

            if (_buffer == null || _buffer.Length != bufferSize)
            {
                throw new InvalidDataException();
            }

            var expectedHash = BufferEx.GetHash(_buffer);

            if (!BufferEx.Equals(actualHash, expectedHash))
            {
                throw new InvalidDataException();
            }

            return(true);
        }
Beispiel #3
0
        private static bool VerifyStartBytes(
            Headers headers, Stream stream)
        {
            var actual = new BinaryReader(stream)
                         .ReadBytes(32);
            var expected = headers.StreamStartBytes;

            return(BufferEx.Equals(actual, expected));
        }