Difference between DESede and TripleDES for cipher.getInstance()
Asked Answered
L

1

24

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?

Linn answered 24/6, 2013 at 16:12 Comment(0)
B
40

"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.

Butlery answered 24/6, 2013 at 17:28 Comment(1)
DESede is descriptive name for 3DES implementation: DESede = DES-Encrypt-Decrypt-Encrypt = Triple DESFauces

© 2022 - 2024 — McMap. All rights reserved.