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?

1 Answer 1

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.

1
  • 6
    DESede is descriptive name for 3DES implementation: DESede = DES-Encrypt-Decrypt-Encrypt = Triple DES
    – Bonewolf
    Commented Aug 27, 2018 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.