Announce two new product: SmartCard Reader Rockey200 and USB2.0 Extension Cable

ROCKEY 200 is a handy and portable USB Smart Card reader that can perform read/write operations on any ISO 7816-1/2/3/4 smart cards which are compatible with protocol T=0 and T=1.

USB2.0 Extension Cable With high speed USB 2.0 devices such as USB token ,USB Card Reader and so on.

Come to try it now!

Error when generating CMAC

Algorithm School

Moderator: UNKNwYSHSA

Posts: 12
Joined: Wed Feb 24, 2016 3:04 am
Points: 128

Error when generating CMAC

Postby Tinatco » Mon Mar 13, 2017 1:48 am

I have to generate CMAC in my applet.But I encountered some problems when doing this and I can't find where I made mistake. Here is my code:

Code: Select all

 Zeros = { 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00}           
 SecretKeySpec desSK = new SecretKeySpec(KeySession,0, 8,"DES");
 Cipher DesCipher = Cipher.getInstance("DES/CBC/NoPadding", "SunJCE");
 Spec = new IvParameterSpec(Zeros);
 DesCipher.init(Cipher.ENCRYPT_MODE, desSK,Spec);
 byte ForLastBlock[] = DesCipher.doFinal(data, 0, 8);
 cipher = Cipher.getInstance("DESede/CBC/NoPadding", "SunJCE");
 Spec = new IvParameterSpec(ForLastBlock);
 cipher.init(Cipher.ENCRYPT_MODE, getKeySpec(KeySession), Spec);
  byte cMac[] = cipher.doFinal(data, 8, 8);   

Hope someone help me out.

Posts: 24
Joined: Mon Nov 30, 2015 3:02 am
Points: 188

Re: Error when generating CMAC

Postby JCaberham » Mon Mar 13, 2017 4:21 am

Your computation method has something wrong. You should notice that: the last block is DES3 encrypted, ICV is last calculated C_MAC

Return to “Algorithm School”

Who is online

Users browsing this forum: No registered users and 1 guest

JavaCard OS : Disclaimer