Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sector authentication succeeds, but reading sector data fails #207

Open
laterdayi opened this issue Feb 12, 2025 · 0 comments
Open

Sector authentication succeeds, but reading sector data fails #207

laterdayi opened this issue Feb 12, 2025 · 0 comments

Comments

@laterdayi
Copy link

laterdayi commented Feb 12, 2025

Sector authentication succeeds, but reading sector data fails

code

 NFCTag tag = await FlutterNfcKit.poll();
    setState(() {
      _tag = tag;
    });
    await FlutterNfcKit.setIosAlertMessage("Working on it...");
    _mifareResult = null;

    if (tag.type == NFCTagType.mifare_classic) {
      final defaultKey = Uint8List.fromList([0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
      bool success = await FlutterNfcKit.authenticateSector(0, keyA: defaultKey);
      if (success) {
        print('authenticateSector success');
        var data = await FlutterNfcKit.readSector(0); // read one sector, or
        var data2 = await FlutterNfcKit.readBlock(0); // read one block
        print(data);
        print(data2);
      } else {
        print('authenticateSector failed');
      }
    }

log

I/flutter (16990): authenticateSector success
E/im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin(16990): Read sector error
E/im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin(16990): java.io.IOException: Transceive failed
E/im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin(16990): 	at android.nfc.TransceiveResult.getResponseOrThrow(TransceiveResult.java:52)
E/im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin(16990): 	at android.nfc.tech.BasicTagTechnology.transceive(BasicTagTechnology.java:154)
E/im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin(16990): 	at android.nfc.tech.MifareClassic.readBlock(MifareClassic.java:431)
E/im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin(16990): 	at im.nfc.flutter_nfc_kit.MifareUtils.readSector(MifareUtils.kt:126)

I found that if you execute the authenticateSector twice then the reading is normal

code

NFCTag tag = await FlutterNfcKit.poll();
    setState(() {
      _tag = tag;
    });
    await FlutterNfcKit.setIosAlertMessage("Working on it...");
    _mifareResult = null;

    if (tag.type == NFCTagType.mifare_classic) {
      final defaultKey = Uint8List.fromList([0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
      bool success = await FlutterNfcKit.authenticateSector(0, keyA: defaultKey);
      if (success) {
        print('authenticateSector success');
        await FlutterNfcKit.authenticateSector(0, keyA: defaultKey);
        var data = await FlutterNfcKit.readSector(0); // read one sector, or
        var data2 = await FlutterNfcKit.readBlock(0); // read one block
        print(data);
        print(data2);
      } else {
        print('authenticateSector failed');
      }
    }

log

I/flutter (16990): authenticateSector success
I/flutter (16990): [44, 122, 185, 207, 32, 8, 4, 0, 4, 253, 133, 164, 78, 121, 80, 144, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 7, 128, 105, 255, 255, 255, 255, 255, 255]
I/flutter (16990): [44, 122, 185, 207, 32, 8, 4, 0, 4, 253, 133, 164, 78, 121, 80, 144]
I/flutter (16990): Instance of 'NFCTag'2222222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant