我正在开发一个 Java 应用程序,我需要通过安全套接字向服务器发送几个字符串,我必须使用由受信任的 CA 生成的我自己的证书
文件证书是 myOwnCRT.crt
客户
InputStream is = new FileInputStream("app.config.properties");
Properties objProperties = new Properties();
objProperties.load(is);
String ipServer = objProperties.getProperty("ip");
String portServer = objProperties.getProperty("port");
SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
SSLSocket socketSsl = (SSLSocket)factory.createSocket(idServer, Integer.parseInt(portServer));
BufferedReader in = new BufferedReader(new InputStreamReader());
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socketSsl.getOutputStream()));
服务器
// System.setProperty("javax.net.ssl.trustStore", "myOwnCRT.crt");
// System.setProperty("javax.net.ssl.keyStorePassword", "pass");
SSLServerSocketFactory fact = (SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
SSLServerSocket socketServidorSsl = (SSLServerSocket)fact.createServerSocket(Integer.parseInt(1099));
SSLSocket socketSsl = (SSLSocket)socketServidorSsl.accept();
BufferedReader entrada = new BufferedReader(new InputStreamReader(socketSsl.getInputStream()));
String line= null;
System.out.println( "Waiting..." );
while( (linea = entrada.readLine()) != null )
{
System.out.println(line);
System.out.flush();
}
我如何通过 SSLSockets 向服务器发送两个字符串?
我希望你能帮助我。
非常感谢