This discussion is archived
5 Replies Latest reply: Apr 4, 2013 12:41 AM by sabre150 RSS

problems with DESede/ECB/NoPadding

843811 Newbie
Currently Being Moderated
I use DESede/ECB/NoPadding and my code works correctly. but when i put some string to encrypt that is not a multiple of 8, as you know, it crash.

Don you know if there are some options that full the code of zeros or something until it is multiple of 8?
  • 1. Re: problems with DESede/ECB/NoPadding
    843811 Newbie
    Currently Being Moderated
    I use DESede/ECB/NoPadding and my code works
    correctly. but when i put some string to encrypt that
    is not a multiple of 8, as you know, it crash.
    DES and DESede require the data length to be a multiple of 8 bytes. Using DESede/ECB/NoPadding, it is your responsibility to force this condition. You could use
    DESede/ECB/PKCS5Padding
    and then the padding to an 8 byte boundary will be done for you.

    If you need to know how PKCS5 padding works, use Google.
  • 2. Re: problems with DESede/ECB/NoPadding
    843811 Newbie
    Currently Being Moderated
    dun forget DESede uses 112 or 168 size keys
  • 3. Re: problems with DESede/ECB/NoPadding
    843811 Newbie
    Currently Being Moderated
    dun forget DESede uses 112 or 168 size keys
    This is a little simplistic as far as the SunJCE JCE provider is concerned.

    A DES key is 56 bits and Triple DES key is either 2x56 bits or 3x56 bits. The first 56 bits
    of 2x56 Bit Triple DES key is used to DES encrypt a block, the second 56 bits is used to
    DES decrypt the the result of the first DES encryption and the first 56 bits is then used
    again to further DES encrypt the block. A 3x56 Bit Triple DES key uses the first 56 bits to
    encrypt a block, the second 56 bits to DES decrypt the result of the first DES encryption
    and then finally the 3rd 56 bit key is used to DES encrypt.

    Within the SunJCE provider, a DES key is packaged as 8 bytes of 7 bits with the least
    significant bit of each byte being a parity bit. I can't remember whether it is even or odd
    parity but it does not matter because the SunJCE provider ignores this bit!

    A Triple DES key is packages as 24 bytes with the first 8 bytes bring used for the DES
    key first encryption stage, the next 8 bytes as the DES key for the decryption stage and
    the last 8 bytes used for the final DES encryption stage. If one tries to provide just 16
    bytes as a representation of the 2x56 Bit key then one gets a
    java.security.InvalidKeyException: Wrong key size
    exception. If one wants the same 56 bit key used for both encryption stages of Triple
    DES encryption then one must build the appropriate 24 bytes.
  • 4. Re: problems with DESede/ECB/NoPadding
    1000959 Newbie
    Currently Being Moderated
    So, it's a slightly old thread, but maybe could you post the code for doing DESede/ECB/NoPadding?
  • 5. Re: problems with DESede/ECB/NoPadding
    sabre150 Expert
    Currently Being Moderated
    997956 wrote:
    So, it's a slightly old thread, but maybe could you post the code for doing DESede/ECB/NoPadding?
    a) DES and DESede are now deprecated in favour of AES.
    b) ECB is generally considered insecure since it allows splicing of ciphertext that will decrypt to valid cleartext. One of the feedback modes should be used.
    c) This site is not a code mill and Google will find many many of examples of this insecure encryption method.