コード例 #1
0
 /// <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;
 }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        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));
            }
        }
コード例 #4
0
ファイル: IsoCard.cs プロジェクト: darko0201/eVR
 public IsoCard(ISCardReader reader)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     this.reader = reader;
 }
コード例 #5
0
 /// <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();
 }
コード例 #6
0
ファイル: IsoReader.cs プロジェクト: thiti-y/pcsc-sharp
        /// <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;
        }
コード例 #7
0
        public ThaiNationalIDCardReader()
        {
            context = ContextFactory.Instance.Establish(SCardScope.System);
            reader  = new SCardReader(context);
            apdu    = new ThaiNationalIDCardAPDUCommandType02();

            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
        }
コード例 #8
0
ファイル: IsoCard.cs プロジェクト: RuiVarela/Nespresso
        public IsoCard(ISCardReader reader, string readerName, SCardShareMode mode, SCardProtocol proto)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            this.reader = reader;
            Connect(readerName, mode, proto);
        }
コード例 #9
0
        /// <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;
        }
コード例 #10
0
ファイル: IsoCard.cs プロジェクト: darko0201/eVR
        public IsoCard(ISCardReader reader, string readerName, SCardShareMode mode, SCardProtocol proto)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            this.reader = reader;
            Connect(readerName, mode, proto);
        }
コード例 #11
0
ファイル: IsoReader.cs プロジェクト: bestpetrovich/pcsc-sharp
        /// <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;
        }
コード例 #12
0
ファイル: IsoReader.cs プロジェクト: vivilyu/SmartCardPlus
        /// <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;
        }
コード例 #13
0
ファイル: Form1.cs プロジェクト: Szynal/PWR-W4-INF
        // 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);
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: scottstephens/pcsc-sharp
        /// <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);
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: scottstephens/pcsc-sharp
        /// <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[] {}));
            }
        }
コード例 #16
0
ファイル: Form1.cs プロジェクト: Szynal/PWR-W4-INF
        // 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[] { });
            }
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: alexpisquared/ng0poc
        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; }
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: thiti-y/pcsc-sharp
        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));
            }
        }
コード例 #19
0
 /// <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);
 }
コード例 #20
0
ファイル: IsoCard.cs プロジェクト: RuiVarela/Nespresso
 public IsoCard(ISCardReader reader)
 {
     if (reader == null)
         throw new ArgumentNullException("reader");
     this.reader = reader;
 }
コード例 #21
0
ファイル: IsoReader.cs プロジェクト: thiti-y/pcsc-sharp
 /// <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);
 }
コード例 #22
0
 public LogedReader(ISCardReader reader)
 {
     _reader = reader;
 }
コード例 #23
0
 public ConnectedReader(string readerName, ISCardContext cardContext)
 {
     Debug.WriteLine("Create Reader TreadID " + Thread.CurrentThread.ManagedThreadId);
     _readerName = readerName;
     _reader     = new SCardReader(cardContext);
 }
コード例 #24
0
 private readonly int _responseApduTrailerLength = 2; // 0x02
 public WrappedReader(ISCardReader reader)
 {
     _reader = reader;
 }