views:

39

answers:

2

So, I have a working protocol that the Client needs to authenticate with user and password to login on the server. Then server and client would trade messages and files. It´s all working OK and I´m using Input/Output Stream for that. I need to add encryption to the conversation and user/password authentication too. I dont want to store a symmetric key inside my jar, So I think I will need a public/private keys for that. I know I could use the public/private encryption to send a symmetric key, but I really dont know how to do that in Java. And I think I could maybe just use encryption on the messages and not on file transfer.

I googled for it and found various ways of using cryptography with java sockets, whats the best(correct) way? Using CipherOutput(Input)Stream? Or is there another way?

If someone could post a piece of code I would be grateful

+2  A: 

SSL. See javax.net.ssl and the JSSE Reference Guide.

EJP
thanks, it looks great and simple, but can I use it with NIO for the server too??
fredcrs
Yes but with great difficulty. See the SSLEngine. But it's not for the faint-hearted.
EJP
A: 

If you are in a bind for time, you can piggy back on SSH port forwarding.

You will setup firewall rule on your server that would allow direct access to clear text port only from the firewall host.

Then on a client you will setup a port forwarding SSH session ( -L option on ssh client ).

The client machine then will talk clear text to a local host on the forwarded port and all conversation will be encrypted by SSH tunnel.

Alexander Pogrebnyak
Its also a good idea, but I need to implement as a commercial software and not beeing able to count with any firewall rule.
fredcrs