예제 #1
0
        /// <summary>
        /// Encrypts packet data
        /// </summary>
        public Span <byte> Encrypt(ReadOnlySpan <byte> data, bool toClient)
        {
            if (!Handshaken || MapleIv == null)
            {
                return(null);
            }

            var newData = new byte[data.Length + 4].AsSpan();
            var header  = newData.Slice(0, 4);
            var content = newData.Slice(4, data.Length);

            data.CopyTo(content);

            if (toClient)
            {
                WriteHeaderToClient(header, data.Length);
            }
            else
            {
                WriteHeaderToServer(header, data.Length);
            }

            EncryptShanda(content);
            AesCipher?.AesTransform(content, MapleIv.Bytes);
            MapleIv.Shuffle();


            return(newData);
        }
예제 #2
0
        /// <summary>
        /// Decrypts a maple packet contained in <paramref name="data"/>
        /// </summary>
        /// <param name="data">Data to decrypt</param>
        public Span <byte> Decrypt(Span <byte> data)
        {
            if (!Handshaken || MapleIv == null)
            {
                return(data);
            }

            var header  = data.Slice(0, 4);
            var length  = GetPacketLength(header);
            var content = data.Slice(4, length);

            AesCipher?.AesTransform(content, MapleIv.Bytes);
            MapleIv.Shuffle();
            DecryptShanda(content);

            return(content);
        }