示例#1
0
        public static Aes ImportBin(this Aes aes, byte[] publicKey)
        {
            //int keyLen = BitConverter.ToInt32(publicKey.Take(4).ToArray(), 0);
            //aes.Key = publicKey.Skip(4).Take(keyLen).ToArray();
            //aes.IV = publicKey.Skip(4 + keyLen).Take(publicKey.Length - 4 - keyLen).ToArray();
            BinaryDataReader reader = new BinaryDataReader((BinaryDataBuffer)publicKey);

            aes.Key = reader.Read <byte[]>();
            aes.IV  = reader.Read <byte[]>();
            return(aes);
        }
示例#2
0
        //SessionID.ToByteArray()
        //.Concat(Ticket.ToByteArray())
        //.Concat(BitConverter.GetBytes(LastTime.ToBinary()))
        //.Concat(CryptoKey)
        //.ToArray();

        public LoginInfo Import(byte[] data)
        {
            BinaryDataReader reader = new BinaryDataReader((BinaryDataBuffer)data);

            SessionID = reader.Read <Guid>();
            Ticket    = reader.Read <Guid>();
            LastTime  = reader.Read <DateTime>();
            CryptoKey = reader.Read <byte[]>();
            //SessionID = new Guid(data.Take(16).ToArray());
            //Ticket = new Guid(data.Skip(16).Take(16).ToArray());
            //LastTime = DateTime.FromBinary(BitConverter.ToInt64(data.Skip(32).Take(8).ToArray(), 0));
            //CryptoKey = data.Skip(40).Take(52).ToArray();
            return(this);
        }
        public override void ReadContentFrom(BinaryDataReader dataReader)
        {
            var protocolVersion = dataReader.Read <UInt16>();

            if ((protocolVersion & 1) == 0)
            {
                throw new NotSupportedException($"Unsupported protocol version {protocolVersion}");
            }

            dataReader.Input.SkipBytes(2);
            dataReader.Read(CalledAETitle);
            dataReader.Read(CallingAETitle);
            dataReader.Read(Reserved);

            Item.ReadItems(dataReader, Items);
        }
        public override void ReadContentFrom(BinaryDataReader dataReader)
        {
            var protocolVersion = dataReader.Read <UInt16>();

            if ((protocolVersion & 1) == 0)
            {
                throw new NotSupportedException($"Unsupported protocol version {protocolVersion}");
            }

            dataReader.Input.SkipBytes(2);
            dataReader.Read(CopiedFromAssociateRequestPDU_1);
            dataReader.Read(CopiedFromAssociateRequestPDU_2);
            dataReader.Read(CopiedFromAssociateRequestPDU_3);

            Item.ReadItems(dataReader, Items);
        }
示例#5
0
 ColumnInfo ReadColumnInfo(BinaryDataReader br)
 {
     try
     {
         ColumnInfo ci = new ColumnInfo()
         {
             DataType    = MdbTypeMap.GetType((MdbType)br.Read <byte>()),
             ColumnSize  = br.Read <int>(),
             AllowDBNull = br.Read <bool>()
         };
         return(ci);
     }
     catch (Exception e)
     {
         throw new DataPackageMessageFormatException(e.Message);
     }
 }
示例#6
0
        public static RSA ImportBin(this RSA rsa, byte[] publicKey)
        {
            //int modLen = BitConverter.ToInt32(publicKey.Take(4).ToArray(), 0);
            //RSAParameters ps = new RSAParameters()
            //{
            //	Modulus = publicKey.Skip(4).Take(modLen).ToArray(),
            //	Exponent = publicKey.Skip(4 + modLen).Take(publicKey.Length - 4 - modLen).ToArray()
            //};
            BinaryDataReader reader = new BinaryDataReader((BinaryDataBuffer)publicKey);
            RSAParameters    ps     = new RSAParameters()
            {
                Modulus  = reader.Read <byte[]>(),
                Exponent = reader.Read <byte[]>()
            };

            rsa.ImportParameters(ps);
            return(rsa);
        }
示例#7
0
        public static PDU ReadHeaderFrom(BufferedStreamReader input)
        {
            var dataReader   = new BinaryDataReader(input, ByteOrder.BigEndian);
            var dataUnitType = (DataUnitType)dataReader.ReadByte();
            var pdu          = PDUFactory.Instance.Create(dataUnitType);

            dataReader.Input.SkipBytes(1);
            pdu.Length = dataReader.Read <UInt32>();
            return(pdu);
        }
        private void ReadQuantizationStepSizes(BinaryDataReader input)
        {
            QuantizationStepSizes = new QuantizationStepSize[input.GetRemainingDatumCount <UInt16>()];

            for (var i = 0; i < QuantizationStepSizes.Length; i++)
            {
                var us = input.Read <UInt16>();
                QuantizationStepSizes[i] = new QuantizationStepSize(us);
            }
        }
示例#9
0
        /// <summary>
        /// Create a new instance of <see cref="DataPackage"/> from <see cref="byte"/> array
        /// using when deserialise <see cref="DataPackage"/> from array created with <see cref="DataPackage.ToArray()"/> methos
        /// </summary>
        /// <param name="data"><see cref="byte"/> array created with <see cref="DataPackage.ToArray()"/> methos</param>
        public DataPackage(byte[] source) : base(null)
        {
            _b  = (BinaryDataBuffer)source;
            _br = new BinaryDataReader(_b);
            _bw = new BinaryDataWriter(_b);

            //Read sizes
            _headerSpaceSize = _br.Read <int>();
            if (_headerSpaceSize < 0)
            {
                throw new DataPackageMessageFormatException("Invalid header size");
            }

            _colCount = _br.Read <int>();
            if (_colCount <= 0 || _colCount > 64192)
            {
                throw new DataPackageMessageFormatException("Invalid columns count, must be more thrn 0 and less then 64192");
            }

            //Read headers
            _headers = new MapTable <string, object>(StringComparer.Ordinal);
            _br.ReadNext();             //Must be Object
            _br.ReadRaw(_headers);
            _br.Position = _headerSpaceSize + header_pos;

            //Read columns
            _indexes = new string[_colCount];
            _colInfo = new ColumnInfo[_colCount];
            for (int i = 0; i < _colCount; i++)
            {
                _br.ReadNext();
                string name = _br.ReadString();
                if (string.IsNullOrEmpty(name))
                {
                    throw new DataPackageMessageFormatException($"Invalid column name for column index {i}");
                }

                _indexes[i] = name;
                _colInfo[i] = ReadColumnInfo(_br);
            }
            _dataPos = _br.Position;
        }
 private void Read_C_ComponentIndex(BinaryDataReader dataReader, int nComponents)
 {
     if (nComponents > 256)
     {
         C_ComponentIndex = dataReader.Read <UInt16>();
     }
     else
     {
         C_ComponentIndex = dataReader.ReadByte();
     }
 }
示例#11
0
 private void Read_SG_Parameters(BinaryDataReader input)
 {
     SG_ProgressionOrder           = (ProgressionOrder)input.ReadByte();
     SG_NumberOfLayers             = input.Read <UInt16>();
     SG_MultipleComponentTransform = (MultipleComponentTransform)input.ReadByte();
 }
示例#12
0
        protected static byte[] Read16BitLengthPrefixedByteArray(BinaryDataReader dataReader)
        {
            var length = dataReader.Read <UInt16>();

            return(dataReader.Input.ReadBytes(length));
        }
示例#13
0
 public override void ReadContentFrom(BinaryDataReader dataReader)
 {
     MaximumNumberOperationsInvoked   = dataReader.Read <UInt16>();
     MaximumNumberOperationsPerformed = dataReader.Read <UInt16>();
 }
示例#14
0
        protected static void Read16BitLengthPrefixedData(BinaryDataReader dataReader, Action readAction)
        {
            var length = dataReader.Read <UInt16>();

            dataReader.Input.Read(length, readAction);
        }
示例#15
0
        public object Read(Type type, BinaryDataReader reader)
        {
            Customer c = new Customer()
            {
                Id           = reader.Read <int>(),
                Title        = reader.Read <string>(),
                RegisterDate = reader.Read <DateTime>()
            };
            int count = reader.Read <int>();

            for (int i = 0; i < count; i++)
            {
                c.AddressList.Add(
                    new Address()
                {
                    Zip          = reader.Read <string>(),
                    Region       = reader.Read <string>(),
                    City         = reader.Read <string>(),
                    Street       = reader.Read <string>(),
                    House        = reader.Read <int>(),
                    Flat         = reader.Read <int>(),
                    RegisterDate = reader.Read <DateTime>()
                }
                    );
            }
            return(c);
        }
示例#16
0
 internal override long ReadContentLength(BinaryDataReader dataReader)
 {
     return(dataReader.Read <UInt32>());
 }
 public override void ReadContentFrom(BinaryDataReader dataReader)
 {
     MaximumLength = dataReader.Read <UInt32>();
 }