Esempio n. 1
0
        static void Main(string[] args)
        {
            try
            {
                readerMgr = new ReaderManagement();
                readerMgr.EstablishContext();

                //List all the available readers
SelectReader:
                reader = ListReaders();

                ////Read Card
                CardHolderPublicData card = ReadCard();
                if (card == null)
                {
                    goto SelectReader;
                }

                ////Read Biometric
                ReadBiometric();

                readerMgr.CloseContext();



                Console.Read();
            }
            catch (MiddlewareException ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
                Console.Read();
            }
        }
Esempio n. 2
0
        static CardHolderPublicData ReadCard()
        {
            System.Threading.Thread.Sleep(1000);
            Console.Clear();

            bool isCardConnected = reader.IsConnected();

            if (!isCardConnected)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Please insert EID Card.");
                Console.ResetColor();

                return(null);
            }

            try
            {
                PublicDataFacade publicDataFacade = reader.GetPublicDataFacade();

                bool isGenuine = publicDataFacade.IsCardGenuine();
                if (!isGenuine)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("The inserted card is not genuine.");
                    Console.ResetColor();

                    return(null);
                }


                CardHolderPublicData output = publicDataFacade.ReadPublicData(true, false, true, false, false);

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Welcome {0}", EmiratesId.AE.Utils.Utils.ByteArrayToUTF8String(output.FullName));
                Console.ResetColor();

                return(output);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Public Data error: {0}", ex.Message);
                Console.ResetColor();

                return(null);
            }
        }
Esempio n. 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);
        }
Esempio n. 4
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            try
            {
                #region Steps 1-5

                readerMgr = new ReaderManagement();
                readerMgr.EstablishContext();

                selectedReader = selectReader();
                IsConnected    = selectedReader.IsConnected();
                isUAE          = ATRSetting.Is_UAE_Card(selectedReader.ATR);

                #endregion Steps 1-5

                #region Step 6

                /* 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();

                #endregion Step 6

                #region Step 7

                /* 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();
                byte[]   csn         = cardInfo.GetCardSerialNumber();
                byte[]   chipSN      = cardInfo.GetChipSerialNumber();
                byte[]   cplc0101    = cardInfo.GetCPLC0101();
                byte[]   cplc9f7f    = cardInfo.GetCPLC9F7F();
                byte[]   isn         = cardInfo.GetIssuerSerialNumber();
                byte[]   irn         = cardInfo.GetIssuerReferenceNumber();
                byte[]   mocSN       = cardInfo.GetMOCSerialNumber();
                byte[]   mocAppState = cardInfo.GetMOCAppletState();
                byte[]   mocAlgVer   = cardInfo.GetMOCAlgorithmVersion();
                byte[]   maxFailed   = cardInfo.GetMaxFailedMatch();
                int      cardVersion = cardInfo.GetCardVersion();
                String   csnHex      = Utils.ByteArrayToHex(csn);

                #endregion Step 7

                #region Step 8

                /* Step 8 : Reading the "Card Holder Public Data", using the "CardHolderPublicData" Class */

                publicDataFacade = selectedReader.GetPublicDataFacade();
                CardHolderPublicData publicData = publicDataFacade.ReadPublicData(true, true, true, true, false);
                byte[] fullNameBin  = publicData.FullName;
                String fullName     = Utils.ByteArrayToUTF8String(fullNameBin);
                byte[] sexBin       = publicData.Sex;
                String sex          = Utils.ByteArrayToUTF8String(sexBin);
                byte[] issueDateBin = publicData.IssueDate;
                String issueDate    = Utils.ByteArrayToStringDate(issueDateBin);
                byte[] photography  = publicData.Photography;
                pictureBox1.Image = (Image) new ImageConverter().ConvertFrom(photography);
                // use publicData.getX as needed
                //…

                #endregion Step 8

                #region Step 9

                /* Step 9 : Reading the "Card Holder Public Data" is extended to support reading additional public data fields
                 *      added in V2 cards such as address, passport information, Company name, Qualification, Field of Study, etc...  */

                CardHolderPublicDataEx publicDataEx = publicDataFacade.ReadPublicDataEx(true, true, true, true, false, true, true, true);
                byte[] fullNameBinEx          = publicDataEx.FullName;
                String fullNameEx             = Utils.ByteArrayToUTF8String(fullNameBin);
                byte[] sexBinEx               = publicDataEx.Sex;
                String sexEx                  = Utils.ByteArrayToUTF8String(sexBin);
                byte[] issueDateBinEx         = publicDataEx.IssueDate;
                String issueDateEx            = Utils.ByteArrayToStringDate(issueDateBin);
                byte[] photographyEx          = publicDataEx.Photography;
                byte[] FieldofStudyEnglishBin = publicDataEx.FieldofStudyEnglish;
                String FieldofStudyEnglish    = Utils.ByteArrayToUTF8String(FieldofStudyEnglishBin);
                byte[] FieldofStudyArabicBin  = publicDataEx.FieldofStudyArabic;
                String FieldofStudyArabic     = Utils.ByteArrayToUTF8String(FieldofStudyArabicBin);

                #endregion

                #region Step 10 "Family Book Data" (Skipped because it needs a special config in sm.cfg)
                /* Step 10 : Reading the "Family Book Data" */

                //FamilyBookDataFacade familyBookDataFacade = selectedReader.GetFamilyBookDataFacade();
                //FamilyBookData familyBookData = familyBookDataFacade.ReadFamilyBookData(false);
                //byte[] firstNameBinChild1 = familyBookData.Child1.FirstNameArabic;
                //String firstNameChild1 = Utils.ByteArrayToUTF8String(firstNameBinChild1);
                #endregion

                #region Step 11 "Verifying Card Genuine in local mode" (Skipped because it needs a special config in sm.cfg)

                /* Step 11 : Verifying Card Genuine in local mode
                 * In order to invoke isCardGenuine() function in the local mode, the sm.cfg configuration file
                 * must be configured as specified in Appendix A, according to the availability of
                 * secure messaging modules (HSM, SAM or multiple SAM, or Software SAM). */

                bool isGenuine = publicDataFacade.IsCardGenuine();

                #endregion



                readerMgr.CloseContext();
            }
            catch (MiddlewareException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }