JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html
https://ftsafe.en.alibaba.com/index.html
calculate MAC value
calculate MAC value
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.
Pls God don't refer me to the Global Platform specification. It's hard for me to understand it well.
Re: calculate MAC value
The related algorithms are defined in ISO 9797.
FYI, here is a sample code from the web to calculate MAC.
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);
Who is online
Users browsing this forum: No registered users and 44 guests