public static byte[] GetPacketDataDecrypted(byte[] data) { byte[] Buffer; using (MemoryStream ms = new MemoryStream(data)) { using (BinaryReader br = new BinaryReader(ms, Encoding.UTF8)) { short PacketLen = br.ReadInt16(); byte pubkey = br.ReadByte(); byte[] content = br.ReadBytes(PacketLen); using (MemoryStream ms2 = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms2)) { byte PubKeyIndex = XCRYPT.GetPubKeyIndex(pubkey); bw.Write(XCRYPT.Decrypt(content, PubKeyIndex, XCRYPT.GameManagerServerPrivKey)); } ms2.Flush(); Buffer = ms2.GetBuffer(); Array.Resize(ref Buffer, content.Length); } } } return(Buffer); }
public ReadPacket(byte[] data) { try { buffer = data; using (MemoryStream ms = new MemoryStream(buffer)) { using (BinaryReader br = new BinaryReader(ms, Encoding.UTF8)) { short PacketLen = br.ReadInt16(); byte pubkey = br.ReadByte(); Head.len = PacketLen; Head.pubkey = pubkey; byte[] content = br.ReadBytes(PacketLen); using (MemoryStream ms2 = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms2)) { byte PubKeyIndex = XCRYPT.GetPubKeyIndex(pubkey); bw.Write(XCRYPT.Decrypt(content, PubKeyIndex, XCRYPT.LoginServerPrivkey)); } ms2.Flush(); body = ms2.GetBuffer(); Array.Resize(ref body, content.Length); } /* * using (MemoryStream ms2 = new MemoryStream()) * { * using (BinaryWriter bw = new BinaryWriter(ms2, Encoding.UTF8)) * { * //byte PubKeyIndex = XCRYPT.GetPubKeyIndex(pubkey); * //bw.Write(XCRYPT.Decrypt(content, PubKeyIndex, XCRYPT.LoginServerPrivkey)); * bw.Write(500); * } * * byte[] buff = ms2.GetBuffer(); * Array.Resize(ref buff, (int)ms2.Length); * body = buff; * * } */ } } Initialized = true; } catch { Initialized = false; return; } }