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.

calculate MAC value

JavaCard Applet Development Related Questions and Answers.
trgorce
Posts: 17
Joined: Mon Feb 29, 2016 2:44 am
Points :146
Contact:

calculate MAC value

Post by trgorce » Mon Mar 07, 2016 3:11 am

I want to open a secure session between my reader and java card. But I don't know how to calculate MAC value.
Pls God don't refer me to the Global Platform specification. It's hard for me to understand it well.

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

Re: calculate MAC value

Post by mabel » Wed Mar 09, 2016 2:09 am

The related algorithms are defined in ISO 9797.

FYI, here is a sample code from the web to calculate MAC.

Code: Select all

byte[] mac;
byte[] icv = new byte[8];
Cipher desedeCBCCipher = Cipher.getInstance("DESede/CBC/NoPadding");
Cipher desCipher = Cipher.getInstance("DES/CBC/NoPadding");

IvParameterSpec ivSpec = new IvParameterSpec(icv);

if (data.length % 8 != 0)
    throw new Exception("data block size must be multiple of 8");

int blocks = data.length / 8;

for (int i = 0; i < blocks - 1; i++) {
    desCipher.init(Cipher.ENCRYPT_MODE, singledesCMAC, ivSpec);
    byte[] block = desCipher.doFinal(data, i * 8, 8);
    ivSpec = new IvParameterSpec(block);
}

int offset = (blocks - 1) * 8;

desedeCBCCipher.init(Cipher.ENCRYPT_MODE, sessionCMAC, ivSpec);
mac = desedeCBCCipher.doFinal(data, offset, 8);

ivSpec = new IvParameterSpec(new byte[8]);
desCipher.init(Cipher.ENCRYPT_MODE, singledesCMAC, ivSpec);
icv = desCipher.doFinal(data);

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 40 guests

JavaCard OS : Disclaimer