Decrypting data from a secure socket

Posted by Ronald on Stack Overflow See other posts from Stack Overflow or by Ronald
Published on 2010-04-05T23:03:15Z Indexed on 2010/04/06 9:03 UTC
Read the original article Hit count: 313

Filed under:
|
|
|
|

I'm working on a server application in Java. I've successfully got past the handshake portion of the communication process, but how do I go about decrypting my input stream? Here is how I set up my server:

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;

import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;

import org.json.me.JSONException;

import dictionary.Dictionary;


public class Server {

    private static int port = 1234;

    public static void main(String[] args) throws JSONException {

        System.setProperty("javax.net.ssl.keyStore", "src/my.keystore");
        System.setProperty("javax.net.ssl.keyStorePassword", "test123");

        System.out.println("Starting server on port: " + port);
        HashMap<String, Game> games = new HashMap<String, Game>();
        final String[] enabledCipherSuites = { "SSL_RSA_WITH_RC4_128_SHA" };

        try{
            SSLServerSocketFactory socketFactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
            SSLServerSocket listener = (SSLServerSocket) socketFactory.createServerSocket(port);
            listener.setEnabledCipherSuites(enabledCipherSuites);
            Socket server; 

            Dictionary dict = new Dictionary();
            Game game = new Game(dict); //for testing, creates 1 global game.
            while(true){
                server = listener.accept(); 
                ClientConnection conn = new ClientConnection(server, game, "User");
                Thread t = new Thread(conn);
                t.start();  
            }
        }
        catch(IOException e){
            System.out.println("Failed setting up on port: " + port);
            e.printStackTrace();
        }
    }
}

I used a BufferedReader to get the data send from the client:

BufferedReader d = new BufferedReader(new InputStreamReader(socket.getInputStream()));

After the handshake is complete it appears like I'm getting encrypted data. I did some research online and it seems like I might need to use a Cipher, but I'm not sure. Any ideas?

© Stack Overflow or respective owner

Related posts about java

Related posts about ssl