| | |
| | | import com.dayu.qiheonlinelibrary.card.UserCard; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author zx |
| | |
| | | int a = 1; |
| | | try { |
| | | MifareClassic mfc = MifareClassic.get(tag); |
| | | List<byte[]> list = new ArrayList<>(); |
| | | if (null != mfc) { |
| | | try { |
| | | //连接NFC |
| | |
| | | //写卡 |
| | | mfc.writeBlock(bIndex + b, data); |
| | | } |
| | | return true; |
| | | int bIndex = mfc.sectorToBlock(1); |
| | | for (int j = 0; j < 3; j++) { |
| | | //读取数据 |
| | | byte[] data = null; |
| | | try { |
| | | data = mfc.readBlock(bIndex); |
| | | bIndex++; |
| | | list.add(data); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if (userCard.equlsUserCard(list)) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | return false; |
| | | } catch (Exception e) { |
| | |
| | | boolean isOpen = mfc.authenticateSectorWithKeyA(sector, defauleKey); |
| | | if (!isOpen) { |
| | | isOpen = mfc.authenticateSectorWithKeyA(sector, companyKey2); |
| | | if (isOpen){ |
| | | if (isOpen) { |
| | | mfc.authenticateSectorWithKeyB(sector, companyKey2); |
| | | } |
| | | } |
| | | if (!isOpen) { |
| | | isOpen = mfc.authenticateSectorWithKeyA(sector, companyKey); |
| | | if (isOpen){ |
| | | if (isOpen) { |
| | | mfc.authenticateSectorWithKeyB(sector, companyKey); |
| | | } |
| | | } |
| | |
| | | //获取写的扇区的块的数量 |
| | | int blockCount = mfc.getBlockCountInSector(sector); |
| | | int blockIndex = mfc.sectorToBlock(sector); |
| | | for (int block = 0; block < blockCount ; block++) { |
| | | for (int block = 0; block < blockCount; block++) { |
| | | // 跳过第 0 扇区的第 0 块 |
| | | if (sector == 0 && block == 0) { |
| | | blockIndex++; |
| | |
| | | mfc.writeBlock(blockIndex, initDataBytes); |
| | | } |
| | | //写卡 |
| | | |
| | | blockIndex++; |
| | | } |
| | | } |