ios NFC encryption functions to achieve

Preface: Record what ios development of NFC add a password function, card type (NFCMiFareTag -> NFCMiFareUltralight), iOS method calls for: sendMiFareCommand.

A, JS code implementation, the NFC-transmitted iOS native method invocation for NTAG216 card type of the card. NTAG212, different NTAG213, NTAG215, NTAG216 configuration position, so just found the card type of configuration starting position. Starting position is arranged NTAG216 E3.

Second, the process of writing the password (0xA2 is a write command, a read command is 0x30)

 let pass = stringToBytes ( '1111'); // password must be transferred to a string of 4 byte method stringToBytes; pass array.
 let pack = stringToBytes ('11 '); // value must be confirmed 2

1, the password is written to E5 position, i.e. the starting position E3 + 2 ;

sendCommand([0xA2, E5, pass[0], pass[1], pass[2], pass[3]]);

2, the PACK (on E6 p, 0-1 bytes) to the desired password confirmation (default is 0x0000).
sendCommand([0xA2, E6, pack[0], pack[1], 0x00, 0x00]);
3, the AUTHLIM (on E4 page, byte 0, bits 2-0) set to the maximum number of failed attempts to verify the password (set to 0 to allow an unlimited number of attempts PWD_AUTH this value). The PROT (on E4 page, word section 0, bit 7) is set to the desired value (= 0 only when needed PWD_AUTH write access, read and write accesses required = 1 PWD_AUTH).
let response = sendCommand ([0x30, E4]); // read page data E4
let response = readResponseE4.result;
let prot = false; // false write is only true for the encryption to encrypt both read and write
let authlim = 0; 
let writeResponse = sendCommand([0xA2, E4, ((response[0] & 0x078) | (prot ? 0x080 : 0x000) | (authlim & 0x007)), response[1], response[2], response[3]]);
4, the AUTH0 (on E3 page 3 bytes) set to a first page should require password verification.
let readResponseE3 = sendCommand ([0x30, 0xE3]); // read page data E3
let writeResponseT = sendCommand ([0xA2, index - 2, readResponseE3.result [0], readResponseE3.result [1], [2], (0 & 0x0ff) readResponseE3.result]); // 0 for the start code to be protected position.
Third, the authentication password (0x1B command to verify)
sendCommand ([0x1B, pass [0 ], pass [1], pass [2], pass [3]]); // pack verified by return values, but also need to verify whether the same local pack
Fourth, remove the password
First you need to verify the password, and then simply AUTH0 (ie configuration start page) is set to 0x0ff can.
let readResponse = sendCommand([0x30, E3]);
let deleteStatu = sendCommand([0xA2, E3, response[0], response[1], response[2], (0x0ff & 0x0ff)]);
Five, ios native method
The need to turn the incoming byte array data type .

- (void)sendMiFareCommand:(NSData *)command completionHandler:(void(^)(NSData *response, NSError * _Nullable error))completionHandler API_AVAILABLE(ios(13.0)) API_UNAVAILABLE(watchos, macos, tvos);

Related Resources
 

Guess you like

Origin www.cnblogs.com/lxh123/p/11699700.html