Last active
May 31, 2023 19:51
-
-
Save hpkaushik121/38efcf301af11eb2d9668a494dfaec5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* p1 &= 0b00111111 = AAC = reject transaction (EMVApplication Authentication Cryptogram) | |
* p1 &= 0b10111111 = TC = proceed offline (Transaction Certificate) | |
* p1 &= 0b01111111 = ARQC = go online (Authorization Request Cryptogram ) + | |
* 0x00 = CDA signature not requested | |
* 0x10 = CDA signature requested | |
*/ | |
ByteArrayOutputStream buf = new ByteArrayOutputStream(); | |
byte[] authorizedAmount = Util.fromHexString("00 00 00 00 01 00"); // 1 Rs | |
byte[] secondaryAmount = Util.fromHexString("00 00 00 00 00 00"); // 0 Rs | |
byte[] tvr = Util.fromHexString("00 00 00 00 00"); //Terminal verification results (TVR) | |
byte[] transactionCurrencyCode = Util.fromHexString("03 56"); // 356 currency code for INR | |
byte[] transactionDate = Util.fromHexString("09 07 23"); // 09/07/2023 | |
byte[] transactionType = Util.fromHexString("00"); // 00 for sale/purchase | |
byte[] terminalUnpredictableNumber = Util.generateRandomBytes(4); | |
byte[] dataAuthenticationCode = new byte[2]; | |
buf.write(authorizedAmount, 0, authorizedAmount.length); | |
buf.write(secondaryAmount, 0, secondaryAmount.length); | |
buf.write(tvr, 0, tvr.length); | |
buf.write(transactionCurrencyCode, 0, transactionCurrencyCode.length); | |
buf.write(transactionDate, 0, transactionDate.length); | |
buf.write(transactionType, 0, transactionType.length); | |
buf.write(terminalUnpredictableNumber, 0, terminalUnpredictableNumber.length); | |
buf.write(iccDynamicNumber, 0, iccDynamicNumber.length); | |
buf.write(dataAuthenticationCode, 0, dataAuthenticationCode.length); | |
byte[] transactionRelatedData = buf.toByteArray(); | |
byte[] cmd = new byte[5+transactionRelatedData.length+1]; | |
cmd[0] = (byte)0x80; //Cls | |
cmd[1] = (byte)0xAE; //INS | |
cmd[2] = (byte)0x40; //P1 | |
cmd[3] = (byte)0x00; //P2 | |
cmd[4] = (byte)transactionRelatedData.length; | |
System.arraycopy(transactionRelatedData, 0, cmd, 5, transactionRelatedData.length); //Data | |
cmd[cmd.length-1] = 0x00; //Le | |
for (byte b : cmd) { | |
System.out.printf("%02X ",b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment