1

Possible Duplicate:
network communication encryption in java

I am designing a client server application. I want the whole session to be encrypted. I was thinking the following precudure to do that(using RSA for public-key encryption and AES-128 for symmetric encryption):

Client connects to server and send a 'hello' message. Server responds with it's public key. Client generates an 128-bit AES key, and sends it encrypted with the server's public key. The rest of the application protocol is encrypted using the AES key.

Is this logic ok? Are there any flaws? Will it be okay or it's better to use SSL? Basically what i am concerned are replay attacks and mitm.

Community
  • 1
  • 1
user969245
  • 83
  • 1
  • 1
  • 8
  • 1
    @dseibert I agree, although the idea to use SSL code base to create your own solution is not a good idea, unless you are an expert (in which case you wouldn't have to ask) – Maarten Bodewes Oct 27 '12 at 21:55

1 Answers1

2

What you are doing is describing the underlying idea of SSL, and as there are many tiny mistakes you can make implementing the scheme, you would be much better off using SSL.

Your scheme would be flawed as you describe it because you don't have any method of verifying the public key of the server. Anyone could have send it. Furthermore, how do you know that the encrypted AES key is actually generated by the client? Anybody may intercept the public key. This is why SSL (or now TLS) uses a truststore and Diffie-Hellman as well, among other tricks.

You can use a self signed certificate which you can trust in some out-of-band procedure (such as distributing with the client app) if you don't want to buy one.

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263