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.

something wrong with TDES to encrypt data

Algorithm School

Moderator: UNKNwYSHSA

Liguwu
Posts: 10
Joined: Thu Apr 07, 2016 1:40 am
Points :78
Contact:

something wrong with TDES to encrypt data

Post by Liguwu » Tue May 24, 2016 1:47 am

Recently, I have completed an applet, in which I use TDES to encrypt data.
But now I am stuck with a problem that I could not pass dofinal function.
Can anyone point what happened?

Code: Select all

public void Encrypt3DES_CBC()
     {
          byte [] keydata = {(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11};
          byte [] input = {(byte)0x22,(byte)0x22,(byte)0x22};
          byte [] output = new byte [100];

          Cipher m_encryptCipher;
          DESKey m_desKey = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES, false);
               
          m_desKey.setKey(keydata,(short)0);
          m_encryptCipher = Cipher.getInstance(Cipher.ALG_DES_CBC_ISO9797_M1, false);
          m_encryptCipher.init(m_desKey,Cipher.MODE_ENCRYPT);
         
          m_encryptCipher.doFinal(input,ISO7816.OFFSET_CDATA,(short)input.length,output,(short)0);
     }

Tarantino
Posts: 101
Joined: Wed Aug 19, 2015 1:56 am
Points :478
Contact:

Re: something wrong with TDES to encrypt data

Post by Tarantino » Tue May 24, 2016 8:47 am

There is something wrong with the last line of your code!
You have put the wrong offset into the input buffer.

Code: Select all

m_encryptCipher.doFinal(input,(short)0,(short)input.length,output,(short)0);
The greatest glory in living lies not in never falling, but in rising every time we fall.--Nelson Mandela

Liguwu
Posts: 10
Joined: Thu Apr 07, 2016 1:40 am
Points :78
Contact:

Re: something wrong with TDES to encrypt data

Post by Liguwu » Tue May 24, 2016 11:42 pm

Hi there! I have solved this problem. You really saved my day! Thanks so much

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 47 guests

JavaCard OS : Disclaimer