// ---------------------------------------------------------------------- private void Monitor_CardInserted(object sender, CardStatusEventArgs e) { logger.Trace("card inserted:"); try { using (var context = ContextFactory.Instance.Establish(SCardScope.System)) { using (var isoReader = new IsoReader( context: context, readerName: readerName, mode: SCardShareMode.Shared, protocol: SCardProtocol.Any, releaseContextOnDispose: true)) { // get UID var command = new CommandApdu(IsoCase.Case2Short, SCardProtocol.Any) { CLA = 0xFF, Instruction = InstructionCode.GetData, P1 = 0x00, P2 = 0x00, Le = 0 // We don't know the ID tag size }; logger.Debug(command.Log()); var response = isoReader.Transmit(command); if (response.Count > 0 && response.StatusWord == 0x9000) { logger.Debug(command.LogData(response)); } else { logger.Debug(command.Log(response)); } // load key command = new CommandApdu(IsoCase.Case3Short, SCardProtocol.Any) { CLA = 0xFF, Instruction = InstructionCode.ExternalAuthenticate, P1 = 0x00, P2 = 0x00, Data = new byte[6] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }; logger.Debug(command.Log()); response = isoReader.Transmit(command); logger.Debug(command.Log(response)); // authenticate command = new CommandApdu(IsoCase.Case3Short, SCardProtocol.Any) { CLA = 0xFF, Instruction = InstructionCode.InternalAuthenticate, P1 = 0x00, P2 = 0x00, Data = new byte[5] { 0x01, 0x00, 0x01, 0x60, 0x00 } }; logger.Debug(command.Log()); response = isoReader.Transmit(command); logger.Debug(command.Log(response)); // read data command = new CommandApdu(IsoCase.Case2Short, SCardProtocol.Any) { CLA = 0xFF, Instruction = InstructionCode.ReadBinary, P1 = 0x00, P2 = 0x01, Le = 0x10 }; logger.Debug(command.Log()); response = isoReader.Transmit(command); if (response.Count > 0 && response.StatusWord == 0x9000) { logger.Debug(command.LogData(response)); } else { logger.Debug(command.Log(response)); } } } } catch (Exception ex) { logger.Error(ex); } }