Пример #1
0
        public static string GetSerialNumber(string readerName)
        {
            string readerSerialNumber;

            using (var reader = new SmartCardReader(readerName))
            {
                var getSerialNumberCommand = new Readers.AViatoR.Components.SerialNumber();

                ConnectToReader(reader);

                try
                {
                    var response = SendCommand(reader, getSerialNumberCommand.GetApdu);
                    readerSerialNumber = getSerialNumberCommand.TranslateResponse(response);
                }
                catch (Exception)
                {
                    // TODO Currently errors are suppressed, maybe should add some way to indicate the reason why serial number is not read
                    return(string.Empty);
                }
                finally
                {
                    if (reader.IsConnected)
                    {
                        reader.Disconnect(CardDisposition.Unpower);
                    }
                }
            }
            return(readerSerialNumber);
        }
Пример #2
0
            public void Run(string readerName)
            {
                var reader = new SmartCardReader(readerName);

                try
                {
                    ReaderHelper.ConnectToReaderWithCard(reader);
                    ReaderHelper.GeneralAuthenticateMifare(reader, 0x04,
                                                           GeneralAuthenticateCommand.MifareKeyType.MifareKeyA, 0x00);
                    // Update block 4 with write operation in value block format:
                    // 4 byte value LSByte first, 4 byte bit inverted represetaton of value LSByte first, 4 byte value LSByte first, 1 byte block address, 1 byte bit inverted block address, 1 byte block address, 1 byte bit inverted block address
                    string valueTypeData = GetMifareValueTypeData(1234567, 0x04);
                    ReaderHelper.UpdateBinaryCommand(reader,
                                                     UpdateBinaryCommand.Type.Plain, 0x04, valueTypeData);

                    SendDecrementCommand(reader, 1, 0x04);
                }
                catch (Exception e)
                {
                    ConsoleWriter.Instance.PrintError(e.Message);
                }
                finally
                {
                    if (reader.IsConnected)
                    {
                        reader.Disconnect(CardDisposition.Unpower);
                    }
                }
            }
Пример #3
0
            public void Run(string readerName, string Keyresponse)
            {
                var reader = new SmartCardReader(readerName);

                try
                {
                    ConsoleWriter.Instance.PrintTask($"Connecting to { reader.PcscReaderName}");
                    ReaderHelper.ConnectToReader(reader);


                    LoadKeyCommand(reader, 0x01,
                                   Readers.AViatoR.Components.LoadKeyCommand.KeyType.CardKey,
                                   Readers.AViatoR.Components.LoadKeyCommand.Persistence.Persistent,
                                   Readers.AViatoR.Components.LoadKeyCommand.Transmission.Plain,
                                   Readers.AViatoR.Components.LoadKeyCommand.KeyLength._6Bytes, Keyresponse);
                }
                catch (Exception e)
                {
                    ConsoleWriter.Instance.PrintError(e.Message);
                }
                finally
                {
                    if (reader.IsConnected)
                    {
                        reader.Disconnect(CardDisposition.Unpower);
                    }
                }
            }
Пример #4
0
            public void Run(string readerName, string data)
            {
                var reader = new SmartCardReader(readerName);

                try
                {
                    Console.WriteLine($"Connecting to {reader.PcscReaderName}");

                    ReaderHelper.ConnectToReaderWithCard(reader);

                    ReaderHelper.GeneralAuthenticateMifare(reader, 0x04,
                                                           GeneralAuthenticateCommand.MifareKeyType.MifareKeyA, 0x01);
                    ReaderHelper.UpdateBinaryCommand(reader, UpdateBinaryCommand.Type.Plain, 0x04, data);     // Data can be 32 bytes long

                    ReaderHelper.GeneralAuthenticateMifare(reader, 0x05,
                                                           GeneralAuthenticateCommand.MifareKeyType.MifareKeyA, 0x01);
                    ReaderHelper.UpdateBinaryCommand(reader, UpdateBinaryCommand.Type.Plain, 0x05, data);

                    ReaderHelper.GeneralAuthenticateMifare(reader, 0x06,
                                                           GeneralAuthenticateCommand.MifareKeyType.MifareKeyA, 0x01);

                    ReaderHelper.UpdateBinaryCommand(reader, UpdateBinaryCommand.Type.Plain, 0x06, data);

                    /*
                     *  ReaderHelper.GeneralAuthenticateMifare(reader, 0x04,
                     *      GeneralAuthenticateCommand.MifareKeyType.MifareKeyA, 0x00);
                     *  ReaderHelper.UpdateBinaryCommand(reader, UpdateBinaryCommand.Type.Plain, 0x04, data);
                     */
                }
                catch (Exception e)
                {
                    ConsoleWriter.Instance.PrintError(e.Message);
                }
                finally
                {
                    if (reader.IsConnected)
                    {
                        reader.Disconnect(CardDisposition.Unpower);
                    }
                }
            }
Пример #5
0
            public void Run(string readerName)
            {
                var reader = new SmartCardReader(readerName);

                try
                {
                    Console.WriteLine($"Connecting to {reader.PcscReaderName}");

                    ReaderHelper.ConnectToReaderWithCard(reader);
                    // Authenticate is SMARTCARDREADER, BLOCK NUMBER, KEYTYPE, KEYSLOT

                    ReaderHelper.GeneralAuthenticateMifare(reader, 0x04,
                                                           GeneralAuthenticateCommand.MifareKeyType.MifareKeyA, 0x01);
                    ReaderHelper.ReadBinaryMifareCommand(reader, 0x04, 0x00);

                    ReaderHelper.GeneralAuthenticateMifare(reader, 0x05,
                                                           GeneralAuthenticateCommand.MifareKeyType.MifareKeyA, 0x01);
                    ReaderHelper.ReadBinaryMifareCommand(reader, 0x05, 0x00);

                    ReaderHelper.GeneralAuthenticateMifare(reader, 0x06,
                                                           GeneralAuthenticateCommand.MifareKeyType.MifareKeyA, 0x01);
                    ReaderHelper.ReadBinaryMifareCommand(reader, 0x06, 0x00);

                    ReaderHelper.GeneralAuthenticateMifare(reader, 0x07,
                                                           GeneralAuthenticateCommand.MifareKeyType.MifareKeyA, 0x01);
                    ReaderHelper.ReadBinaryMifareCommand(reader, 0x07, 0x00);
                }
                catch (Exception e)
                {
                    ConsoleWriter.Instance.PrintError(e.Message);
                }
                finally
                {
                    if (reader.IsConnected)
                    {
                        reader.Disconnect(CardDisposition.Unpower);
                    }
                }
            }