Replies: 2 comments 1 reply
-
What is the error message? |
Beta Was this translation helpful? Give feedback.
-
I'm working on an Ionic project that requires reading data from Mifare Classic NFC cards (both Type A and B). In a Node.js environment, I successfully authenticated and read the card data using a default key ('FFFFFFFFFFFF') and the following code: app.get('/api/nfc-read', async (req, res) => {
if (!currentCard) {
return res.status(400).json({ message: 'No card detected', data: null });
}
try {
const { reader, card } = currentCard;
await reader.authenticate(4, 0x60, 'FFFFFFFFFFFF');
const data = await reader.read(4, 16, 16);
res.json({ message: 'Read successful', data: data.toString('utf8').trim() });
} catch (error) {
console.error('Error reading the card:', error);
res.status(500).json({ message: 'Error reading the card', data: null });
}
}); I am now attempting to implement similar functionality in Ionic. I need to authenticate a block using either key type 'A' or 'B' and read the data from the block. My current approach is as follows: private async authenticateBlock(
blockNumber: number,
key: number[],
keyType: 'A' | 'B',
uid: number[]
): Promise<void> {
const command = keyType === 'A' ? 0x60 : 0x61;
const uidReversed = uid.slice().reverse();
const authCommand = [command, blockNumber, ...key, ...uidReversed];
await Nfc.transceive({
techType: NfcTagTechType.MifareClassic,
data: authCommand,
});
}
private async readBlock(blockNumber: number): Promise<string> {
try {
const { response } = await Nfc.transceive({
techType: NfcTagTechType.MifareClassic,
data: [0x30, blockNumber],
});
return this.bytesToString(response);
} catch (error) {
throw error;
}
} I would like some guidance on properly implementing the authentication in Ionic, especially for both key types ('A' and 'B'). The Node.js approach worked with the default key, but I'm facing challenges in adapting it to work with Ionic's NFC plugin. I tried another configuration to read another type of card with MIFARE Ultralight and the reading worked without problems, I don't think it's a permissions issue. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I am currently working on an Ionic 8 project where I am attempting to authenticate with a MIFARE Classic NFC card. However, I am encountering an authentication error when trying to assign the default key provided on the NFC card. At this point, my objective is to read block 4 of the card, which could be either type A or type B. Despite recognizing the NFC device correctly through the console, the authentication process fails.
Could you please assist me in understanding the possible reasons for this error and how I can resolve the issue? Any guidance or suggestions would be greatly appreciated.
Thank you in advance for your support.
this is the service in ionic:
Service TypeScript
Beta Was this translation helpful? Give feedback.
All reactions