private byte[] decrypt(
      final byte[] inEnc, final int inOff, final int inLen, final byte[] commonMac)
      throws InvalidCipherTextException {
    final byte[] M;
    final byte[] K;
    final byte[] K1;
    final byte[] K2;

    int len;

    // Ensure that the length of the input is greater than the MAC in bytes
    if (inLen <= (CIPHER_MAC_KEY_SIZE / 8)) {
      throw new InvalidCipherTextException("Length of input must be greater than the MAC");
    }

    // 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);

    // Use IV to initialize cipher.
    cipher.init(false, new ParametersWithIV(new KeyParameter(K1), iv));

    M = new byte[cipher.getOutputSize(inLen - mac.getMacSize())];
    len = cipher.processBytes(inEnc, inOff, inLen - mac.getMacSize(), M, 0);
    len += cipher.doFinal(M, len);

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

    // Verify the MAC.
    final int end = inOff + inLen;
    final byte[] T1 = Arrays.copyOfRange(inEnc, end - mac.getMacSize(), end);
    final byte[] T2 = new byte[T1.length];

    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(inEnc, inOff, inLen - T2.length);

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

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

    mac.doFinal(T2, 0);

    if (!Arrays.constantTimeAreEqual(T1, T2)) {
      throw new InvalidCipherTextException("Invalid MAC.");
    }

    // Output the message.
    return Arrays.copyOfRange(M, 0, len);
  }
Decrypts the provided ciphertext.

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