encrypt() public method

public encrypt ( byte packet ) : byte[]
packet byte
return byte[]
Esempio n. 1
0
        private void sendMarginCharData(byte[] data, byte opcode, NetworkStream client, UInt16 shortAfterId, bool isLast)
        {
            // This Method will be used to send the real Data to the client

            // Format for general LoadCharacterReply Responses:
            // 10 00 00 00 <- everytime the same
            // 00 f9 76 04 <- uint32 Char ID
            // 00 00 00 09 <- uint32 number of Character Replys (just raise one up)
            // 00 05 <- viewData opcode (what data is inside) uint16
            // 10 00 <- if it has Data it is 10 00 if not is just 00 00 (and no Data can follow up and packet ends here)
            // e1 00 <- short / uint16 data size
            // DATA
            numCharacterReplies++;

            PacketContent pak = new PacketContent();

            pak.addByte(0x10);
            pak.addUint32(0, 1);
            pak.addUint32(newCharID, 1);
            pak.addUint16(shortAfterId, 1);
            pak.addUintShort(numCharacterReplies);
            if (isLast)
            {
                pak.addUintShort(1);
            }
            else
            {
                pak.addUintShort(0);
            }
            pak.addUintShort(opcode);
            if (data.Length > 0)
            {
                pak.addByteArray(new byte[] { 0x10, 0x00 });
                pak.addUint16((UInt16)data.Length, 1);
                pak.addByteArray(data);
            }
            else
            {
                pak.addByteArray(new byte[] { 0x00, 0x00 });
            }

            Output.WriteDebugLog("[MARGIN SERVER RESPONSE] for OPCODE " + opcode + " : " + StringUtils.bytesToString(pak.returnFinalPacket()));
            byte[] encryptedResponse = marginEncr.encrypt(pak.returnFinalPacket());
            sendTCPVariableLenPacket(encryptedResponse, client);
            System.Threading.Thread.Sleep(50);
        }
Esempio n. 2
0
        private void sendMarginCharData(byte[] data, byte opcode, NetworkStream client)
        {
            // This Method will be used to send the real Data to the client

            // Format for general LoadCharacterReply Responses:
            // 10 00 00 00 <- everytime the same
            // 00 f9 76 04 <- uint32 Char ID
            // 00 00 00 09 <- uint32 number of Character Replys (just raise one up)
            // 00 05 <- viewData opcode (what data is inside) uint16
            // 10 00 <- if it has Data it is 10 00 if not is just 00 00 (and no Data can follow up and packet ends here)
            // e1 00 <- short / uint16 data size
            // DATA

            byte[] header = { 0x10, 0x00, 0x00, 0x00 };
            // Raise one up
            loadCharCounter++;

            // Add the counter
            byte[] counterByte = new byte[4];
            counterByte = NumericalUtils.uint32ToByteArray(loadCharCounter, 1);

            // get the datasize for the packet
            byte[] dataSize = NumericalUtils.uint16ToByteArray((UInt16)data.Length, 1);

            // charId
            byte[] charID = NumericalUtils.uint32ToByteArray(this.newCharID, 0);

            // viewData code
            byte[] responseCode = { 0x00, opcode };

            string pakData = StringUtils.bytesToString_NS(header) +
                             StringUtils.bytesToString_NS(charID) +
                             StringUtils.bytesToString_NS(counterByte) +
                             StringUtils.bytesToString_NS(responseCode);

            string hasData;

            // this needs improvement...
            if (data.Length == 0 && opcode == 0x01)
            {
                hasData = "0000";
            }
            else
            {
                hasData = "1000" + StringUtils.bytesToString_NS(dataSize) + StringUtils.bytesToString_NS(data);
            }

            pakData += hasData;
            PacketContent pak = new PacketContent();

            // Dump the Packet Data to see whats in
            //Console.WriteLine("Response Load Pak : " + pakData);

            // Do the viewData
            byte[] response = StringUtils.hexStringToBytes(pakData);
            Output.WritePacketLog(StringUtils.bytesToString(response), "MARGINSERVER", "0", "0", "0");
            Output.WriteDebugLog("[MARGIN SERVER RESPONSE] for OPCODE " + opcode + " : " + StringUtils.bytesToString(response));
            byte[] encryptedResponse = marginEncr.encrypt(response);
            sendTCPVariableLenPacket(encryptedResponse, client);
            System.Threading.Thread.Sleep(50);
        }