flutter_nfc_kit icon indicating copy to clipboard operation
flutter_nfc_kit copied to clipboard

Add custom read/write helpers for MIFARE Classic tags

Open albertoboccolini opened this issue 6 months ago • 4 comments

This PR introduces two new utility methods for interacting with MIFARE Classic NFC tags:

  • readDataFromTag to read an arbitrary number of bytes from a specified sector/block, skipping trailer blocks automatically.
  • writeDataToTag to write a list of bytes starting from a given sector and block, safely avoiding trailer blocks and padding incomplete blocks with zeros.

They simplify working with MIFARE Classic tags by handling sector authentication, block calculation, and trailer block skipping. Useful for reading or writing multiple bytes without managing low-level NFC logic manually.

albertoboccolini avatar Jun 19 '25 19:06 albertoboccolini

Hi, I'm interested in contributing to this project because I used this library in a project to interact with MiFare Classic tags. I had some difficulty accessing sectors and blocks at a low level, and after seeing that others had similar issues, I thought of implementing some user-friendly methods. This is my first official contribution, so I'm not sure if my approach is entirely correct. I'm open to suggestions and improvements. When you have a moment, could you please review my code? @Harry-Chen

albertoboccolini avatar Jun 19 '25 19:06 albertoboccolini

Thanks! I did have similar plans before, but the issue is that tags might have different keys for different sectors. So I prefer leaving the readBlock API to users.

Harry-Chen avatar Jun 20 '25 05:06 Harry-Chen

You're right, hardcoding a single key for the whole operation limits the real use cases. The idea behind these methods was to provide a high-level function for those dealing with uniformly keyed tags, but we could extend it by adding a Map<int, String> sectorKeysA parameter (and optionally sectorKeysB) to support different keys per sector. Let me know if you think it's worth the PR!

albertoboccolini avatar Jun 26 '25 17:06 albertoboccolini

@Harry-Chen let me know

albertoboccolini avatar Jul 11 '25 12:07 albertoboccolini