private byte[] encrypt(final byte[] in, final int inOff, final int inLen, final byte[] macData)
      throws InvalidCipherTextException {
    final byte[] C;
    final byte[] K;
    final byte[] K1;
    final byte[] K2;

    int len;

    // Block cipher mode.
    K1 = new byte[CIPHER_KEY_SIZE / 8];
    K2 = new byte[CIPHER_MAC_KEY_SIZE / 8];
    K = new byte[K1.length + K2.length];

    kdf.generateBytes(K, 0, K.length);
    System.arraycopy(K, 0, K1, 0, K1.length);
    System.arraycopy(K, K1.length, K2, 0, K2.length);

    // Initialize the cipher with the IV.
    cipher.init(true, new ParametersWithIV(new KeyParameter(K1), iv));

    C = new byte[cipher.getOutputSize(inLen)];
    len = cipher.processBytes(in, inOff, inLen, C, 0);
    len += cipher.doFinal(C, len);

    // Convert the length of the encoding vector into a byte array.
    final byte[] P2 = PARAM.getEncodingV();

    // Apply the MAC.
    final byte[] T = new byte[mac.getMacSize()];

    final byte[] K2hash = new byte[hash.getDigestSize()];
    hash.reset();
    hash.update(K2, 0, K2.length);
    hash.doFinal(K2hash, 0);

    mac.init(new KeyParameter(K2hash));
    mac.update(iv, 0, iv.length);
    mac.update(C, 0, C.length);

    if (P2 != null) {
      mac.update(P2, 0, P2.length);
    }

    if (macData != null) {
      mac.update(macData, 0, macData.length);
    }

    mac.doFinal(T, 0);

    final byte[] Output = new byte[len + T.length];
    System.arraycopy(C, 0, Output, 0, len);
    System.arraycopy(T, 0, Output, len, T.length);

    return Output;
  }
Encrypts the provided plaintext.

@param in The plaintext.
@return The ciphertext.
@throws InvalidCipherTextException Thrown if an error occurred during encryption.
ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/handshake/ecies/ECIESEncryptionEngine.java