Take a look at CryptoHeaven
What you want to write sounds like part of CryptoHeaven instant messaging features. Here is the link http://www.CryptoHeaven.com and the download page is here http://www.cryptoheaven.com/Download/Download.htm
We even provide the entire source code (look in the download page), all is written in pure Java. An OO language not difficult to read. I encourage you to look at our communication layer, stuff in the com.CH_co.cryptx package and and com.CH_cl.service.engine package. This will give you plenty of ideas how to implement your own secure comm prog.
Marcin
________________________________________________
Secure online storage and file sharing http://www.CryptoHeaven.com