Add custom read/write helpers for MIFARE Classic tags
This PR introduces two new utility methods for interacting with MIFARE Classic NFC tags:
readDataFromTagto read an arbitrary number of bytes from a specified sector/block, skipping trailer blocks automatically.writeDataToTagto 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.
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
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.
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!
@Harry-Chen let me know