public static Bytes encryptMsg(final Bytes bytes, final SECPPublicKey remoteKey)
      throws InvalidCipherTextException {
    // TODO: check size.
    final ECIESEncryptionEngine engine = ECIESEncryptionEngine.forEncryption(remoteKey);

    // Do the encryption.
    final Bytes encrypted = engine.encrypt(bytes);
    final Bytes iv = engine.getIv();
    final SECPPublicKey ephPubKey = engine.getEphPubKey();

    // Create the output message by concatenating the ephemeral public key (prefixed with
    // 0x04 to designate uncompressed), IV, and encrypted bytes.
    final MutableBytes answer =
        MutableBytes.create(1 + ECIESHandshaker.PUBKEY_LENGTH + IV_SIZE + encrypted.size());

    int offset = 0;
    // Set the first byte as 0x04 to specify it's an uncompressed key.
    answer.set(offset, (byte) 0x04);
    ephPubKey.getEncodedBytes().copyTo(answer, offset += 1);
    iv.copyTo(answer, offset += ECIESHandshaker.PUBKEY_LENGTH);
    encrypted.copyTo(answer, offset + iv.size());
    return answer;
  }
Encrypts a message for the specified peer using ECIES.

@param bytes The plaintext.
@param remoteKey The peer's remote key.
@return The ciphertext.
@throws InvalidCipherTextException Thrown if encryption failed.
ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/handshake/ecies/EncryptedMessage.java