ResponseAPDU res = ch.transmit(apduBalance);
double balance = 0;
if (res.getSW() != 0x9000){
Utilities.writeToLogs(home,"[E] Error during operation. Remove card from terminal != 0x9000 "+cID);
throw new CardException("Error while reading Card Balance. Aborting operation.");
}
else{
if(verifySignature(res.getData(), 16)){
byte[] plainData = decryptAES128(res.getData(),0,16);
short b = Utilities.getShort(plainData, 0);
balance = (double) (b / 100.0);
return balance;
}
else{
System.out.println("Error during operation. Remove card from terminal");
CARD_LEGIT=false;
Utilities.writeToLogs(home,"[E] Signature failure ---- Error during operation. Remove card from terminal "+cID);
throw new CardException("Signature failure");
}
}
}
else{
Utilities.writeToLogs(home,"[E] Handshake protocol failure "+cID);
System.out.println("Error during operation. Remove card from terminal");
System.exit(-1);
throw new CardException("Handshake protocol failure");
}
}