Change your Java code to use secure sockets layer

If your code already uses socket factories to create its sockets, then you can add secure socket layer (SSL) support to your program. If your code does not already use socket factories, see Change your Java™ code to use socket factories.

To change your code to use SSL, perform the following steps:

  1. Import javax.net.ssl.* to add SSL support:
    import javax.net.ssl.*;
  2. Declare a SocketFactory by using SSLSocketFactory to initialize it:
    SocketFactory newSF = SSLSocketFactory.getDefault();
  3. Use your new SocketFactory to initialize your sockets the same way that you used your old SocketFactory:
    Socket s = newSF.createSocket(args[0], serverPort);

Your code now uses SSL support. You do not need to make any other changes to your code.

See Examples: Change your Java client to use secure sockets layer and Examples: Change your Java server to use secure sockets layer for example code.

Related concepts
Select a digital certificate to use
Use the digital certificate when you run your Java application
Related tasks
Prepare iSeries server for secure sockets layer support
Change your Java code to use socket factories