title: Secret Key SSL Socket connections in Java
body: <p>I'm working on encrypting a tcp connection between a server and a client. In the course of research and testing I'm leaning towards using secret key encryption. My problem is that I cannot find any tutorials on how to implement this feature. The tutorials I have found revolve around one-shot https requests, all I need is a SSL Socket.</p>
  
  <p>The code I've written so far is below. I'm almost certain that it needs to be extended, I just don't know how. Any help is appreciated.</p>
  
  <pre><code>private ServerSocketFactory factory;
  private SSLServerSocket serverSocket;
  
  factory = SSLServerSocketFactory.getDefault();
  serverSocket = (SSLServerSocket) factory.createServerSocket( &lt;portNum&gt; );
  </code></pre>
  
  <p>Server code for accepting client connections</p>
  
  <pre><code>SSLSocket socket = (SSLSocket) serverSocket.accept();
  socket.startHandshake();
  </code></pre>
  
  <p>I just don't know how to actually do the handshake.</p>
  
  <p>reference: <a href="http://docs.oracle.com/javase/1.5.0/docs/guide/security/jsse/JSSERefGuide.html" rel="noreferrer">http://docs.oracle.com/javase/1.5.0/docs/guide/security/jsse/JSSERefGuide.html</a></p>