Page 1 of 1

DES encryption with data length 132 byte

Posted: Thu Mar 09, 2017 11:27 pm
by RexLi
I have to use DES alg in my applet. But the length of Data are 132 bytes. So I wonder if it's feasible to implement DES encryption with data length 132 byte?

Code: Select all

skey = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES,KeyBuilder.LENGTH_DES3_2KEY, false);
cDES = Cipher.getInstance(Cipher.ALG_DES_CBC_ISO9797_M2, false);
     
cDES.init(skey, Cipher.MODE_ENCRYPT);
cDES.doFinal(Data, doffset, dlen, EBuffer, eoffset); // Data and EBuffer are 132 byte length


Re: DES encryption with data length 132 byte

Posted: Fri Mar 10, 2017 6:21 am
by mabel
DES requires the data to be block-aligned to an 8 byte boundary. You can have different length input as long as the cipher instance pads the data. Then the output would be block-aligned.

Re: DES encryption with data length 132 byte

Posted: Fri Mar 10, 2017 8:46 am
by Neqikoo
Under javacard implementation, the padding is done transparently so it can be block-aligned automatically. You don't need to worry about data length.