This article describes how to create a secure socket from an android device to a server using a certificate. It explains how to create a key that Android can use, write a secure server socket, a client socket and send information back and forth between them.
First we can start by downloading the apk file for android and the jar file for your computer (server) along with the correct secure certificate and another certificate to test that other certificates will not work. Download link: http://ece301-examples.googlecode.com/files/ssl_sockets.zip
First I will go through the steps so you can see a working example before looking at the code.
The easiest way to test this:
1. First, make sure that you are using Wifi and that your laptop and your android device are both connected to the same Wifi.
2. From a terminal, run sslsocket.jar with the port number and the whole path of the certificate. In my case:
java -jar sslsocket.jar 9998 /home/juan/testserverkeys
3. Install the APK file in your android device. The certificate is inside the assets folder. When the screen comes up, you need to specify the IP address of your computer, the port number (I used 9998) and a message you like to send over. Then press the SEND button. Look at the image at the start of this article. Should look like that
In your server side you should see the following
Now if you use the wrong certificate:
java -jar sslsocket.jar 9998 /home/juan/testserverWrongKey
You will get an I/O exception in your android application. Try it!

And your server as well will give you an IO exception:

The rest of this article is available for $.99 cents. It has all the source code available to create the apk and jar file and it explains how to create the android SSL certificate as well as the server side certificate.
This article is exclusive, use Cleeng to view it in full.

