fredcrs
fredcrs

Reputation: 3621

How can I add encryption to my own TCP-based-Protocol using Java Sockets?

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

Upvotes: 1

Views: 1289

Answers (2)

Alexander Pogrebnyak
Alexander Pogrebnyak

Reputation: 45576

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.

Upvotes: 0

user207421
user207421

Reputation: 310840

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

Upvotes: 3

Related Questions