Question

I am trying to get TripleDES encryption working in Java. From the Wikipedia article under Keying Options, I want to use option 1, where All three keys are independent.

From the Cipher docs it says to go to the reference guide here, but it still isn't clear to me.

I am working on getting examples running, and use both of these lines in different projects:

Cipher c = Cipher.getInstance("DESede");

Cipher cipher = Cipher.getInstance("TripleDES/ECB/PKCS5Padding");

Both compile fine, so what's the difference? Should I be using one over the other? Do both of these work for using three separate keys?

Was it helpful?

Solution

"TripleDES" is simply an alias for "DESede" in the Sun JCE provider – both return the exact same cipher. "DESede" is the standard name which should work on every Java platform, but in practice, "TripleDES" is probably pretty widely supported too.

According to this page, the SunJCE Triple DES implementation supports options #1 and #2:

Keysize must be equal to 112 or 168.

A keysize of 112 will generate a Triple DES key with 2 intermediate keys, and a keysize of 168 will generate a Triple DES key with 3 intermediate keys.

You should always specify the mode of operation and the padding when instantiating a cipher to make your intents clear. Otherwise the implementation is free to make the choice, which can be confusing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top