public static SSLEngine createSSLEngine(InputStream keyStoreStream,
            String keyStorePassword,
            InputStream trustStoreStream,
            String trustStorePassword,
            boolean isClientMode,
            boolean needTwoWayAuth)
            throws Exception {

        KeyManagerFactory kmf = null;
        TrustManagerFactory tmf = null;
        if (isClientMode || needTwoWayAuth) {
            KeyStore ts = KeyStore.getInstance("JKS");
            try {
                ts.load(trustStoreStream, trustStorePassword.toCharArray());
                tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
                tmf.init(ts);
            } finally {
                if (trustStoreStream != null) {
                    trustStoreStream.close();
                }
            }

        }
        if (!isClientMode || needTwoWayAuth) {
            KeyStore ks = KeyStore.getInstance("JKS");
            try {
                ks.load(keyStoreStream, keyStorePassword.toCharArray());
                kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
                kmf.init(ks, keyStorePassword.toCharArray());
            } finally {
                if (keyStoreStream != null) {
                    keyStoreStream.close();
                }
            }
        }

        SSLContext serverContext = SSLContext.getInstance("TLS");
        serverContext.init(kmf == null ? null : kmf.getKeyManagers(),
                tmf == null ? null : tmf.getTrustManagers(), null);
        SSLEngine sslEngine = serverContext.createSSLEngine();
        sslEngine.setUseClientMode(isClientMode);
        sslEngine.setNeedClientAuth(needTwoWayAuth);

        return sslEngine;
    }
Create a SSL engine

@param keyStoreStream        the key-store stream
@param keyStorePassword      the key-sored password
@param trustStoreStream      the trust-store stream
@param trustStorePassword    the trust-store password
@param isClientMode          whether client mode
@param needTwoWayAuth        Whether require two-way authentication
@return                      the SSL engine
@throws Exception            the exception information while creating
inlong-tubemq/tubemq-core/src/main/java/org/apache/inlong/tubemq/corerpc/utils/TSSLEngineUtil.java