public byte[] ReadByteBlock(int block, byte[] key, NfcKeyType nfcKeyType) { //TODO 4. MIFARE OPERATIONS 2 try { //No card found if (!LoadCurrentMifareClassic()) { return(null); } //Different card ids if (!CheckCardId()) { return(null); } //No authenticated if (!AuthenticateSector(block, nfcKeyType, key)) { return(null); } byte[] data = currentMifareClassic.ReadBlock(block); return(data); } catch { return(null); } }
private bool AuthenticateSector(int block, NfcKeyType nfcKeyType, byte[] key) { int sector = currentMifareClassic.BlockToSector(block); switch (nfcKeyType) { case NfcKeyType.KeyB: return(key != null && currentMifareClassic.AuthenticateSectorWithKeyB(sector, key)); case NfcKeyType.KeyA: default: return(key != null && currentMifareClassic.AuthenticateSectorWithKeyA(sector, key)); } }
public bool WriteByteBlock(int block, byte[] key, byte[] content, NfcKeyType nfcKeyType) { //TODO 4. MIFARE OPERATIONS 3 try { if (content?.Length != 16) { return(false); } //No card found if (!LoadCurrentMifareClassic()) { return(false); } //Different card ids if (!CheckCardId()) { return(false); } //No authenticated if (!AuthenticateSector(block, nfcKeyType, key)) { return(false); } currentMifareClassic.WriteBlock(block, content); return(true); } catch { return(false); } }
public bool WriteByteBlock(int block, byte[] key, byte[] content, NfcKeyType nfcKeyType) { throw new NotImplementedException(); }
public byte[] ReadByteBlock(int block, byte[] key, NfcKeyType nfcKeyType) { throw new NotImplementedException(); }