Example #1
0
        /// <summary>
        /// Initializes a new instance of OutPacket from the given payload data, crypto handler, auth handler, prefix and count.
        /// </summary>
        /// <param name="payload">The ready payload data.</param>
        /// <param name="crypto">The crypto handler to be used.</param>
        /// <param name="auth">The auth handler to be used.</param>
        /// <param name="prefix">The packet's prefix.</param>
        /// <param name="count">The packet's count.</param>
        public OutPacket(byte[] payload, CryptoHandler crypto, AuthHandler auth, short prefix, int count)
        {
            byte[] packetPrefix  = LittleEndian.GetBytes(prefix);
            byte[] packetCount   = LittleEndian.GetBytes(count);
            byte[] iv            = Generate.IV();
            byte[] encryptedData = crypto.EncryptPacket(payload, iv);

            byte[] size = LittleEndian.GetBytes(Convert.ToInt16(16 + encryptedData.Length + 10));

            byte[] authData = Sequence.Concat(packetPrefix, packetCount, iv, encryptedData);
            byte[] hmac     = auth.GetHmac(authData);

            PacketData = Sequence.Concat(size, authData, hmac);
        }