0

In my project I inherited twisted protocol from twisted.internet.protocol import Protocol, As we know, I should do something packet manipulation in the function dataRecieved, However, the doc said:

data: a string of indeterminate length. Please keep in mind that you will probably need to buffer some data, as partial (or multiple) protocol messages may be received! I recommend that unit tests for protocols call through to this method with differing chunk sizes, down to one byte at a time.

So my data format is that: packet len | payload 2 bytes | variable bytes

But things become complected if I want to encrypt my data, How should I do then?

Should I encrypt both packet length and payload? then how to judge if the packet is end?

Or should I encrypt only the payload, then alter the packet length ? what if the encrypted payload length is larger than the max value of 2bytes?

Plus: If I use raw socket instead of twisted, can I omit the 2 bytes packet len prefix?

Thanks!

Alex Chan
  • 1,116
  • 3
  • 15
  • 33
  • `Payload = encrypted_data` don't mix packet pattern with payload content. **You can't encrypted any `ETH` packet header or information contents !**. – dsgdfg Jul 27 '16 at 07:10
  • Of course it's not ETH packet header. packet len is my self-defined pattern in IP layer payload. – Alex Chan Jul 27 '16 at 08:21
  • `Payload= Sub_header + Encrypted_data + Encrypted_data_Len(free size)`. Payload is your message can define any parameter without quota. A `ETH` packet not have only single header, can use your data pattern or `RFC` design. – dsgdfg Jul 27 '16 at 11:57

0 Answers0