Stanislav
Stanislav

Reputation: 87

DSA vs RSA and AES128 vs AES256 encryption in Java

DSA & RSA

It's not about which one is stronger.

I've been researching the subject on the internet and below is the summary of information I've got. Can you please advise if it is correct or not, and if there are any additional important issues which I don't mention here.

Here I am talking only about DSA vs RSA in application to Java. My main goal - to use Public key algorithm to send Session key (AES) from client to server and then to check authencity of client.

DSA.
1. In Java you're are supposed to encrypt the file with private key.
2. It means that IT IS a signature - anyone with a public key can read it, but only the owner can sign it.
3. If you try using public key as private and vice versa, you'll run into trouble, because it is not that difficult to guess public key by private.
4. You effectively can't use DSA to send Session key, because everyone will be able to decrypt it.

RSA.
1. In Java you're are supposed to encrypt file with public key.
2. It means that this is best way to deliver secret messages to one specific recepient. Nobody can read it after being signed, except for the owner.
3. If you try switching keys with each other it will bring troubles (the same as above)
4. You can effectively use RSA for a client to send Session key encrypted with Server's open key and then receive confirmation from servers signed with Client's open key.

Based on this I decided to use RSA for my purposes.

AES256 vs AES128

Another unrelated question - do you think that for session encryption without any extremely sensitive data it makes sense to use AES256?

I'd like to, but it creates problems for end user. I know it is very easy to install update to Java which allows 256 bit keys, but the sad truth is that even such simple thing can cut potential userbase by half.

On the other hand - if I don't send sensitive information (like credit card numbers) and each key is used for not more than a few days, maybe AES128 is enough?

Obviously I am going to include the option to use AES256 for those users who are not bothered by the need to install update.

Thanks for any comments!

Upvotes: 2

Views: 5402

Answers (2)

Paŭlo Ebermann
Paŭlo Ebermann

Reputation: 74800

As you found out, DSA is only a signature algorithm, not a encryption one, and as such not suitable for key exchange.

If you have a online connection (and not just transport from one point to another), you can use Diffie-Hellman (which is based on similar ideas like DSA), and use DSA or RSA in signature mode to authenticate the other side to avoid a man-in-the-middle attack.

Other than that, RSA key exchange is also quite usual (i.e. sending the key AES key encrypted with the RSA key of the server).

For the AES variants, AES-128 should be secure for about any time (i.e. bruteforcing should take longer than you'll live). There is only a larger key variant as the US military wanted to use different levels of security for different stuff. (And also, AES-256 is lately showing some (theoretical) weaknesses which are not in AES-128, which could mean that AES-128 is actually more secure.)

But as Kerrek commented, don't try to invent your own protocol, use existing ones. You will make all mistakes the other ones did before, and add new ones. (You can do your own implementation of these protocols if you want, but it is also often easier and safer to reuse existing implementations, too - there are lots of things to do wrong even with secure protocols, like using bad random numbers.)

For online (two-sided) communication, SSL (or now better its successor TLS) is the way to go. In Java, it is available as the SSLEngine class (if you want to use asynchronous I/O), or with a SSL(Server)SocketFactory (for normal socket read/write). I used this for applet/server communication (for my project fencing-game).

For offline (one-directed) communication (like e-mail) or storage, use the PGP data format (which also can use RSA and AES). (I don't know of an existing Java implementation, though.)

Upvotes: 3

Michael Borgwardt
Michael Borgwardt

Reputation: 346476

DSA means "Digital Signature Algorithm". It's meant for signatures. You cannot use it to encrypt anything.

AES128 is plenty secure enough for sensitive information. Even the US government allows its use for anything except information classified as TOP SECRET, and that only because of a "better safe than sorry" mentality and considering that such information may still be harmful if decoded 50 years from now. I wouldn't hesitate a second to use it for transmitting credit card numbers (which, after all, expire in less than 10 years).

Upvotes: 1

Related Questions