public PutBytes ( byte bdata ) : void | ||
bdata | byte | bytes to add to the data array |
Résultat | void |
private void ReceiveKeyExchange(IAsyncResult ar) { try { if (this.isDisconnected) { return; } if (!sock.Connected) { ClientManager.EnterCriticalArea(); this.Disconnect(); ClientManager.LeaveCriticalArea(); return; } try { stream.EndRead(ar); } catch (Exception) { ClientManager.EnterCriticalArea(); this.Disconnect(); ClientManager.LeaveCriticalArea(); return; } byte[] raw = (byte[])ar.AsyncState; if (raw.Length == 8) { Packet p1 = new Packet(529); p1.PutUInt(1, 4); p1.PutByte(0x32, 8); p1.PutUInt(0x100, 9); Crypt.MakePrivateKey(); string bufstring = Conversions.bytes2HexString(Encryption.Module.getBytes()); p1.PutBytes(System.Text.Encoding.ASCII.GetBytes(bufstring.ToLower()), 13); p1.PutUInt(0x100, 269); bufstring = Conversions.bytes2HexString(Crypt.GetKeyExchangeBytes()); p1.PutBytes(System.Text.Encoding.ASCII.GetBytes(bufstring), 273); SendPacket(p1, true, true); try { byte[] data = new byte[260]; stream.BeginRead(data, 0, 260, this.callbackKeyExchange, data); } catch (Exception) { ClientManager.EnterCriticalArea(); this.Disconnect(); ClientManager.LeaveCriticalArea(); return; } } else if (raw.Length == 260) { Packet p1 = new Packet(); p1.data = raw; byte[] keyBuf = p1.GetBytes(256, 4); Crypt.MakeAESKey(System.Text.Encoding.ASCII.GetString(keyBuf)); StartPacketParsing(); } else if (raw.Length == 529) { Packet p1 = new Packet(); p1.data = raw; byte[] keyBuf = p1.GetBytes(256, 273); Crypt.MakePrivateKey(); Packet p2 = new Packet(260); p2.PutUInt(0x100, 0); string bufstring = Conversions.bytes2HexString(Crypt.GetKeyExchangeBytes()); p2.PutBytes(System.Text.Encoding.ASCII.GetBytes(bufstring), 4); SendPacket(p2, true, true); Crypt.MakeAESKey(System.Text.Encoding.ASCII.GetString(keyBuf)); StartPacketParsing(); } } catch (Exception ex) { Logger.ShowError(ex); } }
private void ReceiveKeyExchange(IAsyncResult ar) { try { if (this.isDisconnected) { return; } if (!sock.Connected) { ClientManager.EnterCriticalArea(); this.Disconnect(); ClientManager.LeaveCriticalArea(); return; } try { stream.EndRead(ar); } catch (Exception) { ClientManager.EnterCriticalArea(); this.Disconnect(); ClientManager.LeaveCriticalArea(); return; } byte[] raw = (byte[])ar.AsyncState; if (raw.Length == 8) { Packet p1 = new Packet(529); p1.PutUInt(1, 4); p1.PutByte(0x32, 8); p1.PutUInt(0x100, 9); Crypt.MakePrivateKey(); string bufstring = Conversions.bytes2HexString(Encryption.Module.getBytes()); p1.PutBytes(System.Text.Encoding.ASCII.GetBytes(bufstring.ToLower()), 13); p1.PutUInt(0x100, 269); bufstring = Conversions.bytes2HexString(Crypt.GetKeyExchangeBytes()); p1.PutBytes(System.Text.Encoding.ASCII.GetBytes(bufstring), 273); SendPacket(p1, true, true); try { byte[] data = new byte[260]; stream.BeginRead(data, 0, 260, this.callbackKeyExchange, data); } catch (Exception) { ClientManager.EnterCriticalArea(); this.Disconnect(); ClientManager.LeaveCriticalArea(); return; } } else if (raw.Length == 260) { Packet p1 = new Packet(); p1.data = raw; byte[] keyBuf = p1.GetBytes(256, 4); Crypt.MakeAESKey(System.Text.Encoding.ASCII.GetString(keyBuf)); StartPacketParsing(); } else if (raw.Length == 529) { Packet p1 = new Packet(); p1.data = raw; byte[] keyBuf = p1.GetBytes(256, 273); Crypt.MakePrivateKey(); Packet p2 = new Packet(260); p2.PutUInt(0x100, 0); string bufstring = Conversions.bytes2HexString(Crypt.GetKeyExchangeBytes()); p2.PutBytes(System.Text.Encoding.ASCII.GetBytes(bufstring), 4); SendPacket(p2, true, true); Crypt.MakeAESKey(System.Text.Encoding.ASCII.GetString(keyBuf)); StartPacketParsing(); } } catch (Exception ex) { Logger.ShowError(ex); } }