private Packet[] ReadAllPackets(byte[] data, byte privKey) { List <Packet> packets = new List <Packet>(); using (MemoryStream ms = new MemoryStream(data)) { using (BinaryReader br = new BinaryReader(ms)) { try { while (br.BaseStream.Position != br.BaseStream.Length) { Packet temp = new Packet(); temp.Length = br.ReadInt16(); temp.pub_key = br.ReadByte(); byte[] content = br.ReadBytes(temp.Length); byte pub_keyindex = XCript.GetPubKeyIndex(temp.pub_key); content = XCript.Decrypt(content, pub_keyindex, privKey); temp.body = content; packets.Add(temp); } return(packets.ToArray()); } catch (Exception e) { Console.WriteLine(e.ToString()); } } } return(packets.ToArray()); }
public void MakePacketAndSend(Socket s, byte[] data) { short ContentLenght = (short)data.Length; byte RandomPubKey = XCript.AddRandPubKey(); using (MemoryStream stream = new MemoryStream()) { int len = 0; using (BinaryWriter bw = new BinaryWriter(stream, Encoding.UTF8)) { bw.Write((short)ContentLenght); bw.Write((byte)RandomPubKey); bw.Write(XCript.Encrypt(data, XCript.GetPubKeyIndex(RandomPubKey), XCript.ZoneServerPrivKey)); len = (int)bw.BaseStream.Length; } stream.Flush(); byte[] buffer = stream.GetBuffer(); Array.Resize(ref buffer, len); GamePacket packet = new GamePacket(buffer, s); this.AddGamePacket(packet); } }
private void MakePacketAndSend(Client MyClient, byte[] content) { short ContentLenght = (short)content.Length; byte RandomPubKey = XCript.AddRandPubKey(); using (MemoryStream stream = new MemoryStream()) { int len = 0; using (BinaryWriter bw = new BinaryWriter(stream, Encoding.UTF8)) { bw.Write((short)ContentLenght); bw.Write((byte)RandomPubKey); bw.Write(XCript.Encrypt(content, XCript.GetPubKeyIndex(RandomPubKey), XCript.ZoneServerPrivKey)); len = (int)bw.BaseStream.Length; } stream.Flush(); byte[] buffer = stream.GetBuffer(); Array.Resize(ref buffer, len); XPacket packet = new XPacket((short)buffer.Length, buffer, MyClient); this.AddPacket(packet); } }