public static ECIESEncryptionEngine forEncryption(final SECPPublicKey pubKey) {
    final SignatureAlgorithm signatureAlgorithm = SignatureAlgorithmFactory.getInstance();

    // Create an ephemeral key pair for IES whose public key we can later append in the message.
    final KeyPair ephKeyPair = signatureAlgorithm.generateKeyPair();

    // Create random iv.
    final byte[] ivb = ECIESHandshaker.random(CIPHER_BLOCK_SIZE).toArray();

    return new ECIESEncryptionEngine(
        signatureAlgorithm.calculateECDHKeyAgreement(ephKeyPair.getPrivateKey(), pubKey),
        ephKeyPair.getPublicKey(),
        ivb);
  }
Creates a new engine for encryption.

<p>The generated IV and ephemeral public key are available via getters {@link #getIv()} and
{@link #getEphPubKey()}.

@param pubKey The public key of the receiver.
@return An engine prepared for encryption.
ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/handshake/ecies/ECIESEncryptionEngine.java