Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

Triple DES in java card

Algorithm School

Moderator: UNKNwYSHSA

user143839285163098
Posts: 5
Joined: Fri Jul 31, 2015 9:34 pm
Points :13
Contact:

Triple DES in java card

Post by user143839285163098 » Mon Jan 25, 2016 2:55 am

I have finished an applet which encodes some information using 3DES with no padding.

Here is part of the applet code in my card.

Code: Select all

        cipherDES = Cipher.getInstance(Cipher.ALG_DES_CBC_NOPAD, false);
        key = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_3KEY, false);
        key.setKey(KEY_BYTES, (short) 0);     

        //Encrypt message
        cipherDES.init(key, Cipher.MODE_ENCRYPT);
        cipherDES.doFinal(tempMessage, startOffset, inLength, tempMessage, startOffset);


The key is 24 bytes length.After I execute the encryption in my card and I obtain the encrypted text.
Then I try to decrypt the encrypted text in the normal Java application but the decrypted text has nothing to do with the original one. Could some one give me any pointers?

Java applet code to decrypt the text is as below:

Code: Select all

byte[] KEY_BYTES = { (byte) 0x38, (byte) 0x12, (byte) 0xA4,
                   (byte) 0x19, (byte) 0xC6, (byte) 0x3B, (byte) 0xE7, (byte) 0x71,
                   (byte) 0x00, (byte) 0x12, (byte) 0x00,(byte) 0x19, (byte) 0x80,
                   (byte) 0x3B, (byte) 0xE7, (byte) 0x71,
                   (byte) 0x39, (byte) 0x12, (byte) 0xA4,
                   (byte) 0x19, (byte) 0xC6, (byte) 0x3C, (byte) 0xE7, (byte) 0x71};
                 
         java.security.spec.AlgorithmParameterSpec alSpec =
            new javax.crypto.spec.IvParameterSpec(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00});

          try {
               Cipher cipher = Cipher.getInstance("DESede/CBC/NoPadding");
               cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(KEY_BYTES,"DESede"),alSpec);
               
               byte[] decrypted = cipher.doFinal(data);
               
               return new String(decrypted);

User avatar
mabel
Posts: 237
Joined: Mon May 18, 2015 3:09 am
Points :1705
Contact:

Re: Triple DES in java card

Post by mabel » Tue Jan 26, 2016 3:35 am

Did you try to use different buffers as input/output for the Cipher.doFinal() method ?

The Cipher.doFinal() method is known for being particularly unpredictable when the input and output buffers overlap.

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 12 guests

JavaCard OS : Disclaimer