When i am going to do SCP01. i can do session key generation and cryptogram generation. I checked cryptogram card and also my self same so my cryptogram generation is right. but when i am going to do mac generation its comming wrong.
i am using default keys as 404142434445464748494a4b4c4d4e4f, so sessionENC key & sessionMAC key same. i think it is right.
sessionENC key = 25 B8 23 AD B1 2B 58 45 3B 33 76 1F 7D 12 C2 37
card cryptogram = 10 9D CC 55 39 F1 35 9C
host cryptogram = 55 52 2B 4 DC 24 E3 27
=> 80 50 00 00 08 1C D3 5A 3A F4 75 97 93 .P.....Z:.u..
(22238 usec)
<= 00 00 FF FF FF FF FF 34 78 DC 2D 01 94 D8 9B 12 .......4x.-.....
14 2A D7 71 10 9D CC 55 39 F1 35 9C 90 00 .*.q...U9.5...
Status: No Error
SEND...
=> 84 82 01 00 10 55 52 2B 04 DC 24 E3 27 DE 0F 95 .....UR+..$.'...
1C A3 73 1A 3D ..s.=
(11463 usec)
<= 69 82 i.
Status: Security condition not satisfied
can u tell me whats wrong in my mac generation...
MAC generation code as
apdu = 8482010010
sessionKey = 25 B8 23 AD B1 2B 58 45 3B 33 76 1F 7D 12 C2 37
public byte[] generateHostMac(byte[] apdu, byte[] sessionKey) {
byte[] mac = new byte[8];
byte[] sessionKey1 = new byte[24];
byte[] padding = { (byte) 0x80, 0, 0 };
byte[] concatenatedChallenges = new byte[24];
byte[] icv = { 0, 0, 0, 0, 0, 0, 0, 0 };
System.arraycopy(sessionKey, 0, sessionKey1, 0, 16);
System.arraycopy(sessionKey, 0, sessionKey1, 16, 8);
System.arraycopy(apdu, 0, concatenatedChallenges, 0, 13);
System.arraycopy(padding, 0, concatenatedChallenges, 13, 3);
try {
SecretKeySpec desKey = new SecretKeySpec(sessionKey1, 0, sessionKey1.length, "DESede");
Cipher cipher = Cipher.getInstance("DESede/CBC/NoPadding");
IvParameterSpec ivSpec = new IvParameterSpec(icv, 0, 8);
cipher.init(Cipher.ENCRYPT_MODE, desKey, ivSpec);
cipher.doFinal(concatenatedChallenges, 0, concatenatedChallenges.length, concatenatedChallenges, 0);
System.arraycopy(concatenatedChallenges, concatenatedChallenges.length - 8, mac, 0, 8);
} catch (Exception e) {
}
return mac;
}