如何通过普通的 Java Socket 套接字实现(SSL/TLS)安全通信

0

如何通过普通的 Java Socket 套接字实现(SSL/TLS)安全通信?

SSLSocket sslSocket = (SSLSocket) ((SSLSocketFactory) SSLSocketFactory.getDefault()).createSocket(
                       socket, 
                       socket.getInetAddress().getHostAddress(), 
                       socket.getPort(), 
                       true);
InputStream inputStream = sslSocket.getInputStream();
OutputStream outputStream = sslSocket.getOutputStream();
// reads from the socket
Scanner scanner = new Scanner(inputStream);
// writes to the socket
OutputStream outputStream = new BufferedOutputStream(outputStream);
如果觉得这对你有用,请随意赞赏,给与作者支持
回答 (0)
0 个回答