/// <summary>Initializes a new instance of the <see cref="IsoReader" /> class that will create its own instance of a <see cref="SCardReader" />.</summary> /// <param name="context">A context to the PC/SC Resource Manager.</param> /// <param name="releaseContextOnDispose">if set to <c>true</c> the <paramref name="context" /> will be released on <see cref="Dispose()" />.</param> /// <exception cref="System.ArgumentNullException">If <paramref name="context" /> is <see langword="null" /></exception> public IsoReader(ISCardContext context, bool releaseContextOnDispose = false) { _context = context ?? throw new ArgumentNullException(nameof(context)); _reader = new SCardReader(context); _releaseContextOnDispose = releaseContextOnDispose; _disconnectReaderOnDispose = true; }
/// <summary> /// Queries the reader's status and prints it out /// </summary> /// <param name="reader">Connected reader</param> private static byte[] PrintReaderStatus(ISCardReader reader) { var sc = reader.Status( out string[] readerNames, // contains the reader name(s) out SCardState state, // contains the current state (flags) out SCardProtocol proto, // contains the currently used communication protocol out byte[] atr); // contains the ATR if (sc != SCardError.Success) { Console.WriteLine("Unable to retrieve card status.\nError message: {0}", Color.Red, SCardHelper.StringifyError(sc)); return(null); } if (atr == null || atr.Length <= 0) { Console.WriteLine("Unable to retrieve card ATR.", Color.Red); return(null);; } Console.WriteLineFormatted("Current reader name: {0}", Color.Yellow, Color.White, reader.ReaderName); Console.WriteLineFormatted("Connected with protocol {0} in state {1}", Color.Yellow, Color.White, proto, state); Console.WriteLineFormatted("Card ATR: {0}", Color.Yellow, Color.White, BitConverter.ToString(atr)); return(atr); }
private static void DisplayReaderStatus(ISCardReader reader) { string[] readerNames; SCardProtocol proto; SCardState state; byte[] atr; var sc = reader.Status( out readerNames, // contains the reader name(s) out state, // contains the current state (flags) out proto, // contains the currently used communication protocol out atr); // contains the ATR if (sc == SCardError.Success) { Console.WriteLine("Connected with protocol {0} in state {1}", proto, state); DisplayCardAtr(atr); Console.WriteLine(); } else { Console.WriteLine("Unable to retrieve card status.\nError message: {0}", SCardHelper.StringifyError(sc)); } }
public IsoCard(ISCardReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } this.reader = reader; }
/// <summary> /// Provides an easy to use CCID wrapper over <see cref="PCSC"/>. /// </summary> /// <remarks><paramref name="ctx"/> and <paramref name="reader"/> are both disposed of upon class destruction or disposal.</remarks> /// <param name="ctx">PCSC carc context</param> /// <param name="reader">PCSC card reader</param> public CCIDDriver(ISCardContext ctx, ISCardReader reader) { Context = ctx ?? throw new ArgumentNullException(); Reader = reader ?? throw new ArgumentNullException(); ReadVersion(); ReadSerial(); byte[] caps = ReadCapabilities(); }
/// <summary>Initializes a new instance of the <see cref="IsoReader" /> class.</summary> /// <param name="reader">The supplied reader will be used for communication with the smart card.</param> /// <param name="disconnectReaderOnDispose">if set to <c>true</c> the supplied <paramref name="reader" /> will be disconnected on <see cref="Dispose()" />.</param> /// <exception cref="System.ArgumentNullException">If reader is <see langword="null" /></exception> public IsoReader(ISCardReader reader, bool disconnectReaderOnDispose = false) { if (reader == null) { throw new ArgumentNullException("reader"); } _reader = reader; _disconnectReaderOnDispose = disconnectReaderOnDispose; }
public ThaiNationalIDCardReader() { context = ContextFactory.Instance.Establish(SCardScope.System); reader = new SCardReader(context); apdu = new ThaiNationalIDCardAPDUCommandType02(); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); }
public IsoCard(ISCardReader reader, string readerName, SCardShareMode mode, SCardProtocol proto) { if (reader == null) throw new ArgumentNullException("reader"); this.reader = reader; Connect(readerName, mode, proto); }
/// <summary>Initializes a new instance of the <see cref="IsoReader" /> class.</summary> /// <param name="reader">The supplied reader will be used for communication with the smart card.</param> /// <param name="disconnectReaderOnDispose">if set to <c>true</c> the supplied <paramref name="reader" /> will be disconnected on <see cref="Dispose()" />.</param> /// <exception cref="System.ArgumentNullException">If reader is <see langword="null" /></exception> public IsoReader(ISCardReader reader, bool disconnectReaderOnDispose = false) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } Reader = reader; _disconnectReaderOnDispose = disconnectReaderOnDispose; }
public IsoCard(ISCardReader reader, string readerName, SCardShareMode mode, SCardProtocol proto) { if (reader == null) { throw new ArgumentNullException("reader"); } this.reader = reader; Connect(readerName, mode, proto); }
/// <summary>Initializes a new instance of the <see cref="IsoReader" /> class that will create its own instance of a <see cref="SCardReader" />.</summary> /// <param name="context">A context to the PC/SC Resource Manager.</param> /// <param name="releaseContextOnDispose">if set to <c>true</c> the <paramref name="context" /> will be released on <see cref="Dispose()" />.</param> /// <exception cref="System.ArgumentNullException">If <paramref name="context" /> is <see langword="null" /></exception> public IsoReader(ISCardContext context, bool releaseContextOnDispose = false) { if (context == null) { throw new ArgumentNullException("context"); } _context = context; _reader = new SCardReader(context); _releaseContextOnDispose = releaseContextOnDispose; _disconnectReaderOnDispose = true; }
// Połączenie z czytnikiem private static bool ConnectReader(ISCardReader reader, string name) { // Przypisanie połączenia do zmiennej var rc = reader.Connect(name, SCardShareMode.Shared, SCardProtocol.Any); // Jeżeli połączono z sukcesem if (rc == SCardError.Success) { return(true); } // Jeżeli nie udało się połączyć return(false); }
/// <summary> /// Connect to reader using <paramref name="name"/> /// </summary> /// <param name="reader">Smartcard reader instance</param> /// <param name="name">Requested reader name</param> /// <returns><c>true</c> if connection attempt was successful</returns> private static bool ConnectReader(ISCardReader reader, string name) { Console.Write($"Trying to connect to reader.. {name}"); var rc = reader.Connect(name, SCardShareMode.Shared, SCardProtocol.Any); if (rc == SCardError.Success) { Console.WriteLine(" done."); return(true); } Console.WriteLine(" failed. No smart card present? " + SCardHelper.StringifyError(rc) + "\n"); return(false); }
/// <summary> /// Receive and print ATR string attribute /// </summary> /// <param name="reader">Connected smartcard reader instance</param> private static void DisplayCardAtr(ISCardReader reader) { byte[] atr; var rc = reader.GetAttrib(SCardAttribute.AtrString, out atr); if (rc != SCardError.Success) { // ATR not supported? Console.WriteLine("Error by trying to receive the ATR. {0}\n", SCardHelper.StringifyError(rc)); } else { Console.WriteLine("ATR: {0}\n", BitConverter.ToString(atr ?? new byte[] {})); } }
// Funkcja wyświetlająca ATR karty znajdującej się w czytniku private void DisplayCardAtr(ISCardReader reader) { byte[] atr; // Pobranie ATR var rc = reader.GetAttrib(SCardAttribute.AtrString, out atr); // W przypadku niepowodzenia if (rc != SCardError.Success) { textBoxATREquals.Text = "Nie udało się połączyć. " + SCardHelper.StringifyError(rc); } else { textBoxATREquals.Text = BitConverter.ToString(atr ?? new byte[] { }); } }
static void DisplayCardAtr(ISCardReader reader) { try { var rc = reader.GetAttrib(SCardAttribute.AtrString, out var atr); if (rc != SCardError.Success) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Error by trying to receive the ATR. {0}", SCardHelper.StringifyError(rc)); } else { Console.ForegroundColor = ConsoleColor.Gray; Console.Write("{0}", BitConverter.ToString(atr ?? new byte[] { })); } } catch (Exception ex) { var c = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"\n{ex}\n"); Console.ForegroundColor = c; } }
/// <summary>Initializes a new instance of the <see cref="IsoReader" /> class and immediately connects to the reader.</summary> /// <param name="reader">The supplied reader will be used for communication with the smart card.</param> /// <param name="readerName">Name of the reader to connect with.</param> /// <param name="mode">The share mode.</param> /// <param name="protocol">The communication protocol. <seealso cref="ISCardReader.Connect(string,SCardShareMode,SCardProtocol)" /></param> /// <param name="disconnectReaderOnDispose">if set to <c>true</c> the supplied <paramref name="reader" /> will be disconnected on <see cref="Dispose()" />.</param> public IsoReader(ISCardReader reader, string readerName, SCardShareMode mode, SCardProtocol protocol, bool disconnectReaderOnDispose = true) : this(reader, disconnectReaderOnDispose) { Connect(readerName, mode, protocol); }
public IsoCard(ISCardReader reader) { if (reader == null) throw new ArgumentNullException("reader"); this.reader = reader; }
public LogedReader(ISCardReader reader) { _reader = reader; }
public ConnectedReader(string readerName, ISCardContext cardContext) { Debug.WriteLine("Create Reader TreadID " + Thread.CurrentThread.ManagedThreadId); _readerName = readerName; _reader = new SCardReader(cardContext); }
private readonly int _responseApduTrailerLength = 2; // 0x02 public WrappedReader(ISCardReader reader) { _reader = reader; }