using NUnit.Framework; using System; using System.Collections.Generic; using System.Text; using NFC; using NFC.Readers.PCSC; using System.Threading; using NFC.Mifare_DESFire; using NFC.Mifare_DESFire.Enums; using NFC.ISO7816_4; using PCSC.Iso7816; using NFC.Crypto; namespace NFC_Test { [TestFixture, Explicit] public class REAL_Windows { [Test] public void GetReaders() { IHardware hardware = new Hardware(); string[] readers = hardware.GetReaders(); Console.WriteLine("Readers detected: {0}", readers.Length); if(readers.Length > 0) { Console.WriteLine("List of ReaderIDs:"); foreach (string readerID in readers) { Console.WriteLine("{0}", readerID); } } } [TestCase("ACS ACR122U PICC Interface 0")] public void Connect(string readerID) { IHardware hardware = new Hardware(); IReader reader = hardware.OpenReader(readerID); bool connected_successfully = false; ReaderEventHandler handler = (sender, card) => { card.Connect(); connected_successfully = true; card.Disconnect(); }; reader.CardDiscovered += handler; reader.Start(); Assert.AreEqual(true, connected_successfully); reader.Stop(); reader.CardDiscovered -= handler; } [TestCase("ACS ACR122U PICC Interface 0")] public void Read(string readerID) { IHardware hardware = new Hardware(); IReader reader = hardware.OpenReader(readerID); bool connected_successfully = false; ReaderEventHandler handler = (sender, card) => { card.Connect(); MIFARE_DESFire desfire = new MIFARE_DESFire(card); desfire.SelectApplication(0x2A472D); Console.WriteLine(HexConverter.ConvertToHexString(desfire.ReadData(0x01, 0x00, 0xF0))); connected_successfully = true; card.Disconnect(); }; reader.CardDiscovered += handler; reader.Start(); Assert.AreEqual(true, connected_successfully); reader.Stop(); reader.CardDiscovered -= handler; } [TestCase("ACS ACR122U PICC Interface 0")] public void Write(string readerID) { IHardware hardware = new Hardware(); IReader reader = hardware.OpenReader(readerID); bool connected_successfully = false; ReaderEventHandler handler = (sender, card) => { card.Connect(); MIFARE_DESFire desfire = new MIFARE_DESFire(card); desfire.SelectApplication(0x2A472D); CipherKey _FabAccess_Application_MasterKey = new CipherKey("50645367566B59703273357638792F42", CipherType.AES, 0x10); desfire.AuthenticateISO_AES(0x00, _FabAccess_Application_MasterKey._Key); desfire.WriteData(0x01, 0x00, HexConverter.ConvertFromHexString("7468656a6f6b6c6c")); connected_successfully = true; card.Disconnect(); }; reader.CardDiscovered += handler; reader.Start(); Assert.AreEqual(true, connected_successfully); reader.Stop(); reader.CardDiscovered -= handler; } } }