Beispiel #1
0
        public NetPacket Encode(NetPacket packet)
        {
            // 필요한 사이즈를 계산하자
            int addSize = packet.Size - packet.GetHeaderSize() + 1;

            if (addSize % 8 != 0)
            {
                addSize = 8 - (addSize % 8);
            }

            // 패킷에 데이터가 남아있지 않으면 새로 할당하자
            packet = CheckAndResizePacket(packet, addSize);

            int headerSize = packet.GetHeaderSize();

            byte[] data = packet.RawData;
            int    size = packet.Size;

            // 체크섬값 초기화
            data[size - 1] = InitChecksumValue;

            // 체크섬값을 마지막에 넣자
            data[size - 1] = GetChecksum(data, headerSize, size - headerSize);

            // tea
            CryptTea.EncryptSimple(data, headerSize, size - headerSize, _keys);

            return(packet);
        }
Beispiel #2
0
        public NetPacket Decode(NetPacket packet)
        {
            int headerSize = packet.GetHeaderSize();
            int size       = packet.Size;

            byte[] data = packet.RawData;

            // tea
            CryptTea.DecryptSimple(data, headerSize, size - headerSize, _keys);

            // checksum
            byte checksum = GetChecksum(data, headerSize, size - headerSize);

            if (InitChecksumValue != checksum)
            {
                throw new Exception("not match packet checksum");
            }

            return(packet);
        }
Beispiel #3
0
 public TeaPacketFilter(int seed = 36324016)
 {
     _keys = CryptTea.GenerateKey(seed);
 }