public string ReadBlock(int sector, int block, string key, byte authentication_mode, bool returnHex = true) { MifareCard card = new MifareCard(MifareCardTypes.Mifare4k); bool readStatus = true; try { if (reader != null) { if (reader.Connect()) { if (authentication_mode == AuthenticationMode.KeyA) { card.SetKeyA(key, sector); card.SetAuthenticationMode(0); } else { card.SetKeyB(key, sector); card.SetAuthenticationMode(1); } if (reader.ReadBlock(card, sector, block)) { if (returnHex) { return(card.GetDataFromLastBlockRead()); } SetData(ConvertHexToString(card.GetDataFromLastBlockRead())); } else { readStatus = false; } } else { throw new Exception("Device not Found"); } } else { throw new Exception("Device not Found"); } if (readStatus) { return(CardData); } throw new Exception("Incorrect Key"); } catch (Exception) { throw; } finally { reader.Disconnect(); } }