private void InvokeSmartCardAdded(ISmartCard smartCard) { if (this.SmartCardAdded != null) { this.SmartCardAdded(smartCard, new SmartCardEventArgs(smartCard)); } }
private async Task OnValidateData(ISmartCard smartCard) { try { // try to get the data var data = await smartCard.GetData(); // if we get here, we got the data AppendText("Retrieved data from card:"); AppendText(data); // Todo: Add validation of data var date = DateTime.Parse(data); if (DateTime.Now > date) { await SetResult(false); } else { await SetResult(true); } } catch (SmartCardException) { AppendText("Error, card not read"); } }
public Startup(ISmartCard smartCard) { _smartCard = smartCard; _smartCard.Authenticated += _smartCard_Authenticated; _smartCard.Connected += _smartCard_Connected; _smartCard.Transmitting += _smartCard_Transmitting; }
private void RemoveSmartCard(ICardReader cardReader) { Trace.Assert(cardReader != null); ISmartCard SmartCard = this.SmartCards[cardReader]; this.SmartCards.Remove(SmartCard); this.InvokeSmartCardRemoved(SmartCard); }
private void AddSmartCard(ICardReader cardReader) { Debug.Assert(cardReader != null); Debug.Assert(cardReader.SmartCard != null); ISmartCard SmartCard = cardReader.SmartCard; this.SmartCards.Add(SmartCard); this.InvokeSmartCardAdded(SmartCard); }
private async Task OnValidatePin(ISmartCard smartCard) { try { // try to get the data var data = await smartCard.GetData(); // if we get here, we got the data AppendText("Successfully validated pin"); AppendText(data); } catch (SmartCardException) { AppendText("Incorrect PIN"); } }
private DataGroupsContent AsDataGroupsContent(ISmartCard smartCard) { Console.WriteLine("start"); var dg1Content = smartCard.DG1().Content(); var dg2Content = smartCard.DG2().Content(); var dg7Content = smartCard.DG7().Content(); var dg11Content = smartCard.DG11().Content(); var dg12Content = smartCard.DG12().Content(); //var cardSecurity = smartCard.CardSecurity().Content(); Console.WriteLine("done"); //return null; return(new DataGroupsContent( dg1Content, dg2Content, dg7Content, dg11Content, dg12Content )); }
private void StartReadCard() { iCard.Connect(reader, SHARE.Shared, PROTOCOL.T0orT1); System.Threading.Thread.Sleep(100); MyKad myKad = new MyKad(iCard); TouchNGoCard tngcard = new TouchNGoCard(iCard); EMVCard emvCard = new EMVCard(iCard); NETSCashCard netsCard = new NETSCashCard(iCard); //check if MyKad if (myKad.SelectApplication()) { myKad.ReadCard(); Card = myKad; } //check if its a touch n go card else if (tngcard.SelectApplication()) { tngcard.ReadCard(); Card = tngcard; } //check if EMV card else if (emvCard.SelectApplication()) { emvCard.ReadCard(); Card = emvCard; } //check if NETS cash card else if (netsCard.SelectApplication()) { netsCard.ReadCard(); Card = netsCard; } else { Card = new UnknownCard(); } iCard.Disconnect(DISCONNECT.Unpower); }
public SmartCardTpduChannel(ISmartCard smartCard) { this.SmartCard.DbC_AssureNotNull(); this.SmartCard = smartCard; }
private bool Connect(String readerName) { SCardError sc = reader.Connect(readerName, SCardShareMode.Shared, SCardProtocol.Any); if (sc != SCardError.Success) return false; byte[] atr = GetATR(readerName); if (atr.Length != 20) // is non-ISO14443A-3 card? { Debug.WriteLine("Can't connect to non-ISO14443A-3-cards."); Disconnect(); return false; } switch (atr[14]) { case 0x01: card = new MifareClassic(MifareClassic.MemorySize.Classic1K); break; case 0x02: card = new MifareClassic(MifareClassic.MemorySize.Classic4K); break; case 0x03: card = new MifareUltralight(); break; case 0x26: card = new MifareClassic(MifareClassic.MemorySize.ClassicMini); break; default: throw new NotImplementedException(); } return true; }
private async Task OnValidateData(ISmartCard smartCard) { try { // try to get the data var data = await smartCard.GetData(); // if we get here, we got the data AppendText("Retrieved data from card:"); AppendText(data); // Todo: Add validation of data var date = DateTime.Parse(data); if(DateTime.Now > date) await SetResult(false); else await SetResult(true); } catch (SmartCardException) { AppendText("Error, card not read"); } }
/// <summary> /// Creates the exception /// </summary> public SmartCardNotConnectedException(ISmartCard smartCard) : base("Smart card is not connected") { this.SmartCard = smartCard; }
/// <summary> /// Creates the exception /// </summary> public SmartCardInUseException(ISmartCard smartCard) : base("Smart card is in use") { this.SmartCard = smartCard; }
/// <summary> /// Creates the exception /// </summary> public SmartCardUnavailableException(ISmartCard smartCard) : base("Smart card is unavailable") { this.SmartCard = smartCard; }
/// <summary> /// Creates the exception /// </summary> public ProtocolNotSupportedException(ISmartCard smartcard, Protocol protocol) : base($"Protocol {protocol} is not supported by the card") { this.Protocol = protocol; this.Smartcard = smartcard; }
public static async Task <TravelCard> ReadTravelCard(ISmartCard card) { using (ISmartCardConnection connection = await card.Connect()) { try { byte[] selection = await connection.Transcieve(Commands.SelectHslCommand); if (selection != null && selection.Length > 0 && selection.SequenceEqual(Commands.OkResponse)) { // Travel card info bytes byte[] appInfo = null; byte[] controlInfo = null; byte[] periodPass = null; byte[] storedValue = null; byte[] eTicket = null; byte[] history = null; // Temporary containers for history chunks byte[] hist1 = new byte[2]; byte[] hist2 = new byte[2]; appInfo = await connection.Transcieve(Commands.ReadAppInfoCommand); controlInfo = await connection.Transcieve(Commands.ReadControlInfoCommand); periodPass = await connection.Transcieve(Commands.ReadPeriodPassCommand); storedValue = await connection.Transcieve(Commands.ReadStoredValueCommand); eTicket = await connection.Transcieve(Commands.ReadETicketCommand); hist1 = await connection.Transcieve(Commands.ReadHistoryCommand); // If we have more history, the last two bytes of the history array will contain the MORE_DATA bytes. if (hist1.Skip(Math.Max(0, hist1.Length - 2)).ToArray() == Commands.MoreDataResponse) { hist2 = await connection.Transcieve(Commands.ReadNextCommand); } // Combine the two history chunks into a single array, minus their last two MORE_DATA bytes history = hist1.Take(hist1.Length - 2) .Concat(hist2.Take(hist2.Length - 2)) .ToArray(); return(TravelCard.CreateTravelCard(appInfo, controlInfo, periodPass, storedValue, eTicket, history)); } else { Debug.WriteLine($"Failed to read travel card. Did not received OK_RESPONSE when trying to select the HSL application."); return(null); } } catch (Exception ex) { Debug.WriteLine($"Failed to read card. Exception: {ex}"); return(null); } } }
/// <summary/> public SmartCardEventArgs(ISmartCard smartCard) { this.SmartCard = smartCard; }