code: private ByteBuffer encryptPacket(ByteBuffer packet) {
          final ByteBuffer payload = (ByteBuffer) ByteBuffer.allocate(SHA1_LENGTH + packet.remaining())
                  .put(sha1(packet))
                  .put((ByteBuffer) packet.flip())
                  .flip();
          final EncryptionResult er = encrypt(password, payload);
          return (ByteBuffer) ByteBuffer.allocate(BUFFER_SIZE)
                  .putShort((short) TYPE_ENCR_AES256)
                  .putShort((short) (ENCRYPT_DATA_LEN + username.length + er.output.remaining()))
                  .putShort((short) username.length)
                  .put(username)
                  .put(er.iv)
                  .put(er.output)
                  .flip();
      }
docs: Encrypts the provided packet, so it's can't be eavesdropped during a transfer
  to a CollectD server. Wire format:
  <pre>
  +---------------------------------+-------------------------------+
  ! Type (0x0210)                   ! Length                        !
  +---------------------------------+-------------------------------+
  ! Username length in bytes        ! Username                      \
  +-----------------------------------------------------------------+
  ! Initialization Vector (IV)      !                               \
  +---------------------------------+-------------------------------+
  ! Encrypted bytes (AES (SHA1(packet) + packet))                   \
  +---------------------------------+-------------------------------+
  </pre>
  
  @see <a href="https://collectd.org/wiki/index.php/Binary_protocol#Encrypted_part">
  Binary protocol - CollectD | Encrypted part</a>