Hi,
I started working on ARPC verification. For that i need to generate my own ARPC in chip card. i worked on that as per emv standards.
Code: Select all
public void generateSecondAC(APDU apdu, byte[] apduBuffer) {
byte[] iad = new byte[8];
byte[] atcBuffer = new byte[8];
// First 2 bits of P1 specify the type
// These bits also have to be returned, as the Cryptogram Information
// Data (CID);
// See Book 3, Sect 6.5.5.4 of the Common Core Definitions.
byte cid = (byte) (apduBuffer[OFFSET_P1] & 0xC0);
if (cid == RFU_CODE || cid == ARQC_CODE) {
// not a request for TC or AAC
ISOException.throwIt(SW_WRONG_P1P2);
}
short dataLen = apduBuffer[OFFSET_LC];
Util.arrayCopy(apduBuffer, (short) 5, onlineARPC, (short) 0, (short) 8);
Util.arrayCopy(apduBuffer, (short) 0x0D, responseCode, (short) 0, (short) 2);
byte[] Y = new byte[8];
// XOR between ARQC and Response Code as per mentioned in ARPC method 1 EMV book 2 (8.2.1)
Y = xor(chipMAC, responseCode);
Signature sig = Signature.getInstance(Signature.ALG_DES_MAC8_ISO9797_1_M2_ALG3, false);
sig.init(theCrypto.sk, Signature.MODE_SIGN);
short resultLen = sig.sign(Y, (short) 0, (short) (8), apduBuffer, (short) (dataLen + 10));
apdu.setOutgoingAndSend((short) (dataLen + 10), (short) (resultLen));
}
public static byte[] xor(byte[] arqc, byte[] responseCode) {
byte[] c = new byte[arqc.length];
for (short i = 0; i < arqc.length; i++) {
c[i] = (byte) (arqc[i] ^ responseCode[i]);
}
return c;
}
But it is not generating correct. Can you review it