public bool WriteKeyA(MifareCard card, string data, int sector) { if (data.Length == MifareCard.NumberOfCharactersInKey) { if (!ReadBlock(card, sector, MifareCard.KeyBlock)) { return(false); } string originalData = card.GetDataFromLastBlockRead(); string newData = data + originalData.Substring(MifareCard.NumberOfCharactersInKey); if (card.GetCurrentAuthenticatedSector() == sector) { return(WriteBlockWithoutAuth(card, newData, sector, MifareCard.KeyBlock)); //block #3 is sector trailer } else { if (AuthenticateSector(card, sector)) { return(WriteBlockWithoutAuth(card, newData, sector, MifareCard.KeyBlock)); } else { throw new Exception("Authentication failed for the specified key.");; } } } else { throw new ArgumentOutOfRangeException("The key must be 12 characters."); } }
public bool WriteBlock(MifareCard card, byte[] data, int sector, int block) { if (data.Length == MifareCard.NumberOfBytesInABlock) { if (card.GetCurrentAuthenticatedSector() == sector) { return(WriteBlockWithoutAuth(card, data, sector, block)); } else { if (AuthenticateSector(card, sector)) { return(WriteBlockWithoutAuth(card, data, sector, block)); } else { throw new Exception("Authentication failed for the specified key.");; } } } else { throw new ArgumentOutOfRangeException("Data must be 16 bytes."); } }
public bool ReadBlock(MifareCard card, int sector, int block) { if (card.GetCurrentAuthenticatedSector() == sector) { return(ReadBlockWithoutAuth(card, sector, block)); } else { if (AuthenticateSector(card, sector)) { return(ReadBlockWithoutAuth(card, sector, block)); } else { return(false); } } }
public bool WriteBlock(MifareCard card, string data, int sector, int block) { if (data.Length == MifareCard.NumberOfCharactersInABlock) { if (card.GetCurrentAuthenticatedSector() == sector) { return(WriteBlockWithoutAuth(card, data, sector, block)); } else { if (AuthenticateSector(card, sector)) { return(WriteBlockWithoutAuth(card, data, sector, block)); } else { return(false); } } } return(false); }
public bool WriteKeys(MifareCard card, string keyA, string keyB, int sector, string accessbits) { if (keyA.Length == 12 && keyB.Length == 12) { if (!ReadBlock(card, sector, 3)) { return(false); } string keyString = keyA + accessbits + keyB; if (card.GetCurrentAuthenticatedSector() == sector) { WriteBlockWithoutAuth(card, keyString, sector, 3); } else { if (AuthenticateSector(card, sector)) { if (WriteBlockWithoutAuth(card, keyString, sector, 3)) { return(true); } else { return(false); } } else { return(false); } } } return(false); }