Encryption scheme advice please!

Hi all,

I am trying to implement a client/server messaging scheme over a network socket.

I have never performed any kind of encryption before, so this is my first try!

I am currently trying to get it to work with the following scheme in order to establish communication using symmetric encryption:

1) server generates a "RSA/ECB/PKCS1Padding" asymmetric key pair (for each client) with a 512-bit key size.

2) server sends the serialised public key part of this pair and an md5 hash of the public key to the client

3) client verifies the public key with the hash and deserialises it into a PublicKey object.

4) client generates a symmetric key (128-bit "AES/None/NoPadding") and IV (128-bit, using SecureRandom "SHA1PRNG")

5) client sends symmetric key and IV to server, encrypted asymmetrically using servers' public key, and a hash as above

6) communication can now continue back and forth with symmetric encryption.

I have the following questions:

a) is this scheme any good?!

b) should I incorporate signatures for any of these messages? if so, where?

c) my attempts to implement signatures ("MD5withRSA") always returns false when I attempt to verify. The sender creates a signature of the message using the senders private key. The recipient attempts to verify the signature with the public key part of the pair. What am I doing wrong?!

d) have I chosen suitable algorithms, i.e. "RSA/ECB/PKCS1Padding", "AES/None/NoPadding" and "MD5withRSA"? And the key sizes?

e) presumably, if I implement signatures, I don't also have to produce hashes, since the signatures always contain a hash? If this is the case, how do I verify the content of the message, since I can't access the hash part of the signature in order to compare? The signature itself only authenticates the message - is that right?

Any help with any of this is much appreciated - why do things like this have to be so complicated?!

Thanks in advance!

[2029 byte] By [scuzziea] at [2007-11-27 4:55:55]
# 1
Why aren't you using SSL?
ejpa at 2007-7-12 10:10:59 > top of Java-index,Security,Cryptography...
# 2

Would that be better? What's the advantage?

Please don't tell me that coding all that was a waste of time!

I don't know if it's relevant, but the server will be running on port 80 and there is also some UDP communication involved, and long connection times - can SSL deal with this?

I was under the impression that SSL is for HTTPS, i.e. request/response - I assume that's wrong then?

scuzziea at 2007-7-12 10:10:59 > top of Java-index,Security,Cryptography...
# 3

> Would that be better?

Yes.

> What's the advantage?

1. It is written.

2. It is mature.

3. There are no known attacks. Do you have a cryptological proof of your design's security?

4. It is built into Java.

> Please don't tell me that coding all that was a waste of time!

All that coding was a waste of time. [I asked you not to tell me that, 99!]

> I don't know if it's relevant, but the server will be

> running on port 80 and there is also some UDP

> communication involved, and long connection times -

> can SSL deal with this?

Port 80 is for plaintext HTTP. If your protocol isn't plaintext and/or isn't HTTP you shouldn't use port 80. The server would need to run on port 443 if it is doing encrypted HTTP.The port number is irrelevant to UDP as UDP port numbers are in a separate space. Encryption over UDP is just too hard, forget it now.

> I was under the impression that SSL is for HTTPS,

SSL is for TCP. HTTPS is HTTP over SSL over TCP, just as HTTP is directly over TCP.

> i.e. request/response - I assume that's wrong then?

yep, it is wrong.

ejpa at 2007-7-12 10:10:59 > top of Java-index,Security,Cryptography...
# 4

Okay, next step I guess is to find out how to implement that (as I said, I am new to all this).

Can you advise on what my next steps should be? And perhaps hint at which tools I should be using? I've done everything so far using the Netbeans 5.5 & JDK6 bundle. [Perhaps I should have mentioned that I'm completely new to Java as well...]

scuzziea at 2007-7-12 10:10:59 > top of Java-index,Security,Cryptography...
# 5
http://java.sun.com/j2se/1.5.0/docs/guide/security/jsse/JSSERefGuide.html
ejpa at 2007-7-12 10:10:59 > top of Java-index,Security,Cryptography...
# 6
Thank you very much for your help.Is NetBeans + JDK enough? Or should I install other tools which could help me?
scuzziea at 2007-7-12 10:10:59 > top of Java-index,Security,Cryptography...
# 7
The JDK is all you need.
ejpa at 2007-7-12 10:10:59 > top of Java-index,Security,Cryptography...