public CardHolderPublicDataEx ReadCard()
        {
            ReaderManagement readerMgr = new ReaderManagement();

            readerMgr.EstablishContext();
            readerMgr.DiscoverReaders();
            PCSCReader       selectedReader   = readerMgr.Readers[0];
            bool             IsConnected      = selectedReader.IsConnected();
            bool             isUAE            = ATRSetting.Is_UAE_Card(selectedReader.ATR);
            PublicDataFacade publicDataFacade = selectedReader.GetPublicDataFacade();

            // Step 6 : In order to use EIDA "secure messaging" in "local mode", the function
            // "IDCardWrapper.LoadConfiguration" shall be called to load the "secure messaging modules configurations"
            // from the sm.cfg file "C:\Program Files\EIDA Toolkit\Libs\sm.cfg"
            // Sample configuration of is described in appendix A.
            IDCardWrapper.LoadConfiguration();

            /* Step 7 : Once PCSCReader object is acquired in a CONNECTED state and with right type,
             *      application can extract the EIDA ID Card related information such as Card Serial Number, and Chip Serial Number.
             *      The retrieved information will be in binary format. By using the format conversion functions of the Toolkit,
             *      Developers can convert data from binary format to string representation. Refer to Utils class for a sample conversion implementation. */

            CardInfo cardInfo    = selectedReader.GetCardInfo();
            int      cardVersion = cardInfo.GetCardVersion();

            if (cardVersion < 2)
            {
                throw new System.Exception("خطأ : البطاقة المستخدمة ذات إصدار قديم وغير صالحة للقراءة. برجاء تحديث البطاقة");
            }

            CardHolderPublicDataEx result = publicDataFacade.ReadPublicDataEx(true, true, true, true, false, true, false, true);

            readerMgr.CloseContext();
            return(result);
        }
示例#2
0
        static PCSCReader ListReaders()
        {
            readerMgr.DiscoverReaders();
            var readers = readerMgr.Readers;
            int option;

            if (readers.Length == 1)
            {
                return(readers[0]);
            }

            //Return as default reader if only one is found.
List:
            Console.Clear();
            Console.WriteLine("Available Readers:\n==============================================");
            for (int i = 0; i <= readers.Length - 1; i++)
            {
                Console.WriteLine("{0}) {1}", (i + 1), readers[i]);
            }

            Console.Write("Please enter the reader number:");
            if (!Int32.TryParse(Console.ReadLine(), out option))
            {
                goto List;
            }
            else
            {
                if (option < 1 || option > readers.Length)
                {
                    goto List;
                }
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\"{0}\" selected.", readers[option - 1].ReaderName);
            Console.ResetColor();

            return(readers[option - 1]);
        }
示例#3
0
        public static EIDModel CreateFromEIDReader()
        {
            EIDModel         model = new EIDModel();
            ReaderManagement readerManager;
            PCSCReader       reader;

            try
            {
                //System.Windows.Forms.MessageBox.Show("before reader");
                readerManager = new ReaderManagement();
                readerManager.EstablishContext();
                readerManager.DiscoverReaders();
                //System.Windows.Forms.MessageBox.Show("after reader discover");
                if (readerManager.Readers.Length > 0)
                {
                    reader = readerManager.Readers[0];
                    if (reader.IsConnected())
                    {
                        //System.Windows.Forms.MessageBox.Show("after connection to reader, before getting data");
                        PublicDataFacade       pDataFacade = reader.GetPublicDataFacade();
                        CardHolderPublicData   pData       = pDataFacade.ReadPublicData(true, true, true, true, false);
                        CardHolderPublicDataEx pDataEx     = pDataFacade.ReadPublicDataEx(true, false, true, true, false, true, true, true);

                        model.EIDNumber = Utils.ByteArrayToUTF8String(pData.IdNumber);
                        model.Phone     = Utils.ByteArrayToUTF8String(pDataEx.HomeAddress.ResidentPhoneNumber);
                        model.Mobile    = Utils.ByteArrayToUTF8String(pDataEx.HomeAddress.MobilePhoneNumber);
                        model.Email     = Utils.ByteArrayToUTF8String(pDataEx.HomeAddress.Email);
                        model.Pobox     = Utils.ByteArrayToUTF8String(pDataEx.HomeAddress.POBox);
                        model.Emirate   = Utils.ByteArrayToUTF8String(pDataEx.HomeAddress.EmirateDescriptionEnglish);
                        model.City      = Utils.ByteArrayToUTF8String(pDataEx.HomeAddress.CityDescriptionEnglish);
                        model.Area      = Utils.ByteArrayToUTF8String(pDataEx.HomeAddress.AreaDescriptionEnglish);

                        model.Sex        = Utils.ByteArrayToUTF8String(pData.Sex);
                        model.Occupation = Utils.ByteArrayToUTF8String(pData.Occupation);
                        model.Occupation = Utils.ByteArrayToUTF8String(pDataEx.OccupationEnglish);
                        model.Occupation = Utils.ByteArrayToUTF8String(pDataEx.OccupationArabic);
                        model.Occupation = Utils.ByteArrayToUTF8String(pDataEx.OccupationTypeEnglish);
                        model.Occupation = Utils.ByteArrayToUTF8String(pDataEx.OccupationTypeArabic);

                        model.ResidencyType = Utils.ByteArrayToHex(pData.ResidencyType, "");
                        model.DOB           = Utils.ByteArrayToStringDate(pData.DateOfBirth).Replace("/", "-");

                        model.ResidencyExpiry = Utils.ByteArrayToStringDate(pData.ResidencyExpiryDate);
                        model.Name            = RemoveComma(Utils.ByteArrayToUTF8String(pData.FullName));
                        model.NameAr          = RemoveComma(Utils.ByteArrayToUTF8String(pData.ArabicFullName));

                        model.Title          = Utils.ByteArrayToUTF8String(pData.Title);
                        model.TitleAr        = Utils.ByteArrayToUTF8String(pData.ArabicTitle);
                        model.NationalityID  = (Utils.ByteArrayToUTF8String(pData.Nationality));
                        model.PassportNumber = Utils.ByteArrayToUTF8String(pDataEx.PassportNumber);

                        model.SponsorType   = Utils.ByteArrayToHex(pData.SponsorType, "");
                        model.SponsorNumber = Utils.ByteArrayToHex(pData.SponsorNumber, "");
                        model.SponsorName   = Utils.ByteArrayToUTF8String(pData.SponsorName);
                        model.CompanyName   = Utils.ByteArrayToUTF8String(pDataEx.CompanyNameEnglish);
                        if (pData.ResidencyNumber != null)
                        {
                            model.ResidencyNumber = Utils.ByteArrayToUTF8String(pData.ResidencyNumber).Trim();
                        }

                        model.PhotoPath = @"C:\Temp\EID_PHO_" + model.EIDNumber.Replace(" ", "").Trim() + ".jpg";
                        model.Photo     = pData.Photography;
                        if (pData.Photography != null)
                        {
                            System.IO.MemoryStream ms    = new System.IO.MemoryStream(pData.Photography);
                            System.Drawing.Image   image = System.Drawing.Image.FromStream(ms);
                            image.Save(model.PhotoPath, System.Drawing.Imaging.ImageFormat.Jpeg);
                        }

                        model.Signature = pDataEx.HolderSignatureImage;
                        if (pDataEx.HolderSignatureImage != null)
                        {
                            System.IO.MemoryStream ms    = new System.IO.MemoryStream(pDataEx.HolderSignatureImage);
                            System.Drawing.Image   image = System.Drawing.Image.FromStream(ms);
                            image.Save(@"C:\Temp\EID_SIG_" + model.EIDNumber.Replace(" ", "").Trim() + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                        model.HasData = true;
                    }
                }
            }
            catch (Exception ex)
            {
                model.HasData = false;
                Console.WriteLine("ERROR: " + ex.Message);
            }
            return(model);
        }
示例#4
0
 private PCSCReader selectReader()
 {
     readerMgr.DiscoverReaders();
     PCSCReader[] readers = readerMgr.Readers;
     return(readers[0]);
 }