English 中文(简体)
如何编制袖珍的方案规划
原标题:how to do ssl socket programming
  • 时间:2011-07-22 07:31:00
  •  标签:
  • java
  • ssl

我正在通过Follwing IP地址进行电话通信,但我不想以斜体的方式进行通信,但我如何能够改变<代码>。 InetAddress服务器Addr = InetAddress.getByName(“192.168.1.2”); to SSL.

public class TCPClient implements Runnable {

    public void run() {

     try {

         InetAddress serverAddr = InetAddress.getByName("192.168.1.2");

             Log.d("TCP", "C: Connecting...");

             Socket socket = new Socket(serverAddr,12345);

             String message = "Hello from Client android emulator";
              try {

                     Log.d("TCP", "C: Sending:  " + message + " ");

                     PrintWriter out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true);

                     out.println(message);

                     Log.d("TCP", "C: Sent.");

                 Log.d("TCP", "C: Done.");



         } catch(Exception e) {

             Log.e("TCP", "S: Error", e);
                 } finally {

                    socket.close();

                  }
     } catch (Exception e) {

          Log.e("TCP", "C: Error", e);

     }

}

}
问题回答

Create SSLSocket instead of Socket. Rest is the same.

SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket("192.168.1.2", 12345);

您不妨补充特殊物质特性。 你们必须这样做:

To authenticate the server, the client s trust store must contain the server s certificate. Client SSL with server authentication is enabled by the URL attribute ssl or the property ssl set to peerAuthentication. In addition, the system properties javax.net.ssl.trustStore and javax.net.ssl.trustStorePassword need to be set.:

System.setProperty("javax.net.ssl.trustStore","clientTrustStore.key");
System.setProperty("javax.net.ssl.trustStorePassword","qwerty");

如果服务器确实对客户进行认证,客户将需要一个关键的配对机和客户证书:

System.setProperty("javax.net.ssl.keyStore","clientKeyStore.key");
System.setProperty("javax.net.ssl.keyStorePassword","qwerty");

基本上,你需要使用SSLS电话,用于在 Java的SSL通信。

在设立特别安全等级表时,你首先需要配置用于核查服务器证书的信托库。

然后,你需要获得特别安全等级表,并与服务器连接,然后开始与服务器进行双手。

一旦手法成功完成,你就可以开始与服务器交换应用数据,通常像其他便衣连接一样。

A HTTPS的客户和HTTPS服务器在 Java提供如何在 Java建立SSL服务器和SSL客户的词汇。 它非常有用。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签