NFC Read and Write
NFC Read and Write
1.1 M1 card is the most famous and most widely used non-contact card (such as campus card, bus card,
etc.) of NXP (Philips) Company.。
1.2 The CPU card refers to a smart card with 8/16/32-bit CPU and logic processing capability.
1. Reader mode;
3. Point-to-point mode;
Reference to:http://blog.csdn.net/u011115385/article/details/50401272
Reference to:http://www.cnblogs.com/jyycnblogs/p/5077609.html
mfc.connect();
3 Decrypted sector
auth = mfc.authenticateSectorWithKeyA(sector,MERCHANT_KEY);
4 Calculate the current block number (0~63) to get the entire data of the current block
byte[] data = mfc.readBlock(currBlock);//get currBlock block data
5 Converted to a hexadecimal string, according to "Linux machine standard card format 170410" to
obtain the required data
mfc.connect();
3 Decrypted sector
4 Calculate the current block number (0~63) to get the entire data of the current block
5 Wallet verify
1)Verify Address
3)Verify whether left (right) wallet inversion and inversion wallet are equal
4)Whether the left (right) wallet and the backup area wallet are equal
5)The above four kinds of comparisons take exception to the data in the backup area
6 Restructure wallet data
isodep.connect();
3 Reading the directory, returning the last 4 digits of 9000 for success, or failure
4 Reading balance, returning the last 4 digits of 9000 for success, or failure
byte[] balance = {(byte) 0x80, (byte) 0x5C, 0x00, 0x02, 0x04};
byte[] balanceRsp = isodep.transceive(balance);
isodep.connect();
3 Reading the directory, returning the last 4 digits of 9000 for success, or failure
/**
* Read MF directory
* CLA 80; INS 50;P1 00;P2 02;Lc 02(The length of the file name);Data 3F(file name);Le 00
* First read the directory, the next initialization of the Redeposit command operation can be
successful, otherwise 6985
*/
String mfHxs = "00A40000023F01";
byte[] mfRsp = isodep.transceive(HexStringToByteArray(mfHxs));
4 Redeposit initialization operation, returning the last 4 digits of 9000 for success, or failure
/**
* Initialization Redeposit command
* CLA 80; INS 50;P1 00;P2 02;Lc 0B;Data such as ;le 10
* Key index 1 byte; transaction amount 4 bytes; terminal number 6 bytes
*/
// Key Identifier: The key identifier in the IC card
String keyLogo = "01";
// Initialization Redeposit command
// String cmd1 = "805000020B"+"01"+"00000064"+"000013000000"+"10";
String cmd1 = "805000020B" + keyLogo + transationMenoy + terminalNum + "10";
Log.d(TAG, "cmd1:" + cmd1);
// Initialize the Redeposit and return the result
byte[] res1 = isodep.transceive(HexStringToByteArray(cmd1));
5 Redeposit command
// Process key original data(4-byte random number + 2-byte electronic passbook or Wallet
online transaction number +8000)
String str1 = "F09AF5BD00028000";
//MAC original data(4-byte transaction amount + 1 byte transaction type identifier + 6-
byte terminal number + 4 bytes host transaction date + 3 bytes host transaction time)
String str2 = "000000640200001300000020170616160447";
// Authorization key
String str3 = "1122334455667788";
//snake: fixed value
String str4 = "26911300";
// Card physical card number
String str5 = "8D7FC6A5";
//call “so”file to get MAC
String mac = NfcUtil.add(HexStringToByteArray(str1), HexStringToByteArray(str2),
HexStringToByteArray(str3), HexStringToByteArray(str4), HexStringToByteArray(str5));
4)Execute the redeposit command and return the result. The last 4 digits of 9000
represent success, or fail.
/**
* redeposit command
* CLA 80; INS 52;P1 00;P2 02;Lc 0B;Data such as;Le 04
* Transaction date (host) 4 bytes; transaction time (host) 3 bytes; MAC2 4 bytes
*/
str5 = ByteArrayToHexString(tag.getId());
String mac = getMac(res1);
String cmd2 = "805200000B" + getCurrentData() + mac.substring(0, 8) + "04";
Log.e("TAG", "CMD2==" + cmd2);
byte[] res2 = isodep.transceive(HexStringToByteArray(cmd2));
5 Remark
3 M1 card reference standard file: Linux machine standard card format 170410.xlsx
4 CPU card storage method: Shenzhen Cardlan Technology CPU card demand 20170510.doc
Enclose Command Reference Page 89: New FMCOS 2.0 User Manual.pdf
6 Difficulties
Such as string:JAVA[String]、JNI[jstring]、C[char*]
Effect: Set the value of the first n bytes of the opened memory space s to the value c.