Ejemplo n.º 1
0
        private void btnVerify_Click(object sender, EventArgs e)
        {
            try
            {
                MyKad_SDK.CBM_Init();
                int iReturn = -1;

                MyKad_SDK.CBM_RdrName[] dlgRdr = new MyKad_SDK.CBM_RdrName[100];
                iReturn = MyKad_SDK.CBM_Enumerate(dlgRdr);

                VerifyForm dlg = new VerifyForm(GetThumb1Path(), GetThumb2Path());
                dlg.ShowDialog();


                if (File.ReadAllText(Path.Combine(_workDirectory, _verifyStatus)) == "SUCCESS")
                {
                    ProfileInfo.IsVerified = true;
                }
                else
                {
                    ProfileInfo.IsVerified = false;
                }

                UpdateUI();
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 2
0
 private void DisconnectSmartCard()
 {
     try
     {
         MyKad_SDK.CardDisconnect();
         MyKad_SDK.CloseReader();
     }
     catch
     {
     }
 }
Ejemplo n.º 3
0
        private void RefreshReader()
        {
            int  ContextHandle = 0;
            uint readerCount   = 0;

            byte[]        pbyReaderNames = new byte[152];
            StringBuilder readerList     = new StringBuilder();

            int status = MyKad_SDK.SCardEstablishContext(0, 0, 0, ref ContextHandle);

            if (status != 0)
            {
                return;// FpReturn.ErrorSCardEstablishContext;
            }
            status = MyKad_SDK.SCardListReaders(ContextHandle, null, pbyReaderNames, out readerCount);
            if (status != 0)
            {
                return;// FpReturn.ErrorSCardListReaders;
            }
            byte[] rdr = new byte[readerCount];
            status = MyKad_SDK.SCardListReaders(ContextHandle, null, rdr, out readerCount);
            if (status != 0)
            {
                return;// FpReturn.ErrorSCardListReaders;
            }
            string strRdrName = null;

            for (int i = 0; i < readerCount; i++)
            {
                strRdrName += Convert.ToChar(rdr[i]);
            }

            string[] RdrName = strRdrName.Split('\0');
            comboBox1.Items.Clear();
            for (int i = 0; i < RdrName.Count(); i++)
            {
                if (!string.IsNullOrEmpty(RdrName[i]))
                {
                    comboBox1.Items.Add(RdrName[i]);
                    if (RdrName[i].Contains("CT01 2"))
                    {
                        comboBox1.Text = RdrName[i];
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public string[] RefreshReaderList()
        {
            int  ContextHandle = 0;
            uint readerCount   = 0;

            byte[]        pbyReaderNames = new byte[152];
            StringBuilder readerList     = new StringBuilder();

            int status = MyKad_SDK.SCardEstablishContext(0, 0, 0, ref ContextHandle);

            if (status != 0)
            {
                return(null);
            }

            status = MyKad_SDK.SCardListReaders(ContextHandle, null, pbyReaderNames, out readerCount);
            if (status != 0)
            {
                return(null);
            }

            byte[] rdr = new byte[readerCount];
            status = MyKad_SDK.SCardListReaders(ContextHandle, null, rdr, out readerCount);
            if (status != 0)
            {
                return(null);
            }
            string strRdrName = null;

            for (int i = 0; i < readerCount; i++)
            {
                strRdrName += Convert.ToChar(rdr[i]);
            }

            string[] rdrs = strRdrName.Split('\0');
            _rdrList = new List <string>();
            for (int i = 0; i < rdrs.Count(); i++)
            {
                if (!string.IsNullOrEmpty(rdrs[i]))
                {
                    _rdrList.Add(rdrs[i]);
                }
            }
            return(_rdrList.ToArray());
        }
Ejemplo n.º 5
0
        private void btnVerify_Click(object sender, EventArgs e)
        {
            try
            {
                MyKad_SDK.CBM_Init();
                int iReturn = -1;

                MyKad_SDK.CBM_RdrName[] dlgRdr = new MyKad_SDK.CBM_RdrName[100];
                iReturn = MyKad_SDK.CBM_Enumerate(dlgRdr);


                VerifyForm dlg = new VerifyForm(_mp.MyKad.GetThumb1Path(), _mp.MyKad.GetThumb2Path());
                dlg.ShowDialog();
                //frmVerify2 f = new frmVerify2(_mp.MyKad.GetThumb1Path(), _mp.MyKad.GetThumb2Path());
                //f.ShowDialog();

                if (File.ReadAllText(Path.Combine(_mp.MyKad.GetWorkDirectory(), _mp.MyKad.GetVerifyStatus())) == "SUCCESS")
                {
                    _mp.UserProfile.IsVerified = true;
                    txtStatus.Text             = "VERIFIED";
                    txtStatus.BackColor        = Color.Green;
                    txtStatus.Update();
                    Thread.Sleep(500);
                    _mp.ShowForm(FormType.MainForm);
                }
                else
                {
                    _mp.UserProfile.IsVerified = false;
                    MessageBox.Show("Verification failed. Please try again.");
                }
                // UpdateUI();
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 6
0
        private FpReturn ConnectSmartCard(string reader)
        {
            int  status        = 0;
            int  state         = 0;
            int  ContextHandle = 0;
            uint readerCount   = 0;

            byte[]        pbyReaderNames = new byte[152];
            StringBuilder readerList     = new StringBuilder();

            status = MyKad_SDK.SCardEstablishContext(0, 0, 0, ref ContextHandle);
            if (status != 0)
            {
                return(FpReturn.ErrorSCardEstablishContext);
            }

            //status = MyKad_SDK.SCardListReaders(ContextHandle, null, pbyReaderNames, out readerCount);
            //if (status != 0)
            //    return FpReturn.ErrorSCardListReaders;


            //byte[] rdr = new byte[readerCount];
            //status = MyKad_SDK.SCardListReaders(ContextHandle, null, rdr, out readerCount);
            //if (status != 0)
            //    return FpReturn.ErrorSCardListReaders;
            //string strRdrName = null;
            //for (int i = 0; i < readerCount; i++)
            //{
            //    strRdrName += Convert.ToChar(rdr[i]);

            //}

            //string[] RdrName = strRdrName.Split('\0');


            MyKad_SDK.CBM_RdrName[] dlgRdr = new MyKad_SDK.CBM_RdrName[100];
            MyKad_SDK.CBM_Init();
            status = MyKad_SDK.CBM_Enumerate(dlgRdr);

            MyKad_SDK.CloseReader();

            status = MyKad_SDK.OpenReader();
            if (status != 0)
            {
                return(FpReturn.ErrorOpenReader);
            }

            //string reader = IniFile.IniReadValue("device.ini", "Reader", "Name", @"IRIS BCR200DTP 11111001130700207 CT01 2");
            //string reader = comboBox1.Text;
            status = MyKad_SDK.SelectDevice(reader, reader.Length);
            if (status != 0)
            {
                return(FpReturn.ErrorSelectDevice);
            }

            status = MyKad_SDK.CardDetect(ref state);
            if (status != 0)
            {
                return(FpReturn.ErrorCardDetect);
            }

            status = MyKad_SDK.CardConnectA();
            if (status != 0)
            {
                return(FpReturn.ErrorCardConnectA);
            }

            status = MyKad_SDK.SelectPTS(0x13 /*38400bps*/);
            if (status != 0)
            {
                return(FpReturn.SelectPTS);
            }

            return(FpReturn.Success);
        }
Ejemplo n.º 7
0
        private FpReturn ReadJPN(out List <string> strList, out byte[] fp1, out byte[] fp2, out Image img)
        {
            //string APIname = "";
            int status = 0;
            int state  = 88;

            byte[] temp = new byte[80];
            strList = new List <string>();
            //sb = new StringBuilder();
            ////ClearScreen();
            //Application.DoEvents();
            fp1 = null;
            fp2 = null;
            img = null;

            try
            {
                //btnReadMyKad.Enabled = false;

                status = MyKad_SDK.SelJPNApp();
                if (status != 0)
                {
                    return(FpReturn.ErrorSelJPNApp);
                }

                ResetByteArray(ref temp);
                status = MyKad_SDK.JPN_GMPCName(temp);
                if (status != 0)
                {
                    return(FpReturn.ErrorJPN_GMPCName);
                }
                strList.Add(string.Format("{0}={1}", "JPN_GMPCName", ConvertByteToString(temp).Trim()));

                ResetByteArray(ref temp);
                status = MyKad_SDK.JPN_IDNum(temp);
                if (status != 0)
                {
                    return(FpReturn.ErrorJPN_IDNum);
                }
                strList.Add(string.Format("{0}={1}", "JPN_IDNum", ConvertByteToString(temp).TrimEnd('\0')));

                ResetByteArray(ref temp);
                status = MyKad_SDK.JPN_Address1(temp);
                if (status != 0)
                {
                    return(FpReturn.ErrorJPN_Address1);
                }
                strList.Add(string.Format("{0}={1}", "JPN_Address1", ConvertByteToString(temp)).TrimEnd('\0'));

                ResetByteArray(ref temp);
                status = MyKad_SDK.JPN_Address2(temp);
                if (status != 0)
                {
                    return(FpReturn.ErrorJPN_Address2);
                }
                strList.Add(string.Format("{0}={1}", "JPN_Address2", ConvertByteToString(temp)).TrimEnd('\0'));

                ResetByteArray(ref temp);
                status = MyKad_SDK.JPN_Address3(temp);
                if (status != 0)
                {
                    return(FpReturn.ErrorJPN_Address3);
                }
                strList.Add(string.Format("{0}={1}", "JPN_Address3", ConvertByteToString(temp).TrimEnd('\0')));

                ResetByteArray(ref temp);
                status = MyKad_SDK.JPN_Postcode(temp);
                if (status != 0)
                {
                    return(FpReturn.ErrorJPN_Postcode);
                }

                string postcode = string.Empty;
                int    i        = 0;
                foreach (byte single in temp)
                {
                    postcode += single.ToString("X2");
                    if (2 == i++)
                    {
                        break;
                    }
                }
                postcode = postcode.Substring(0, 5);
                strList.Add(string.Format("{0}={1}", "JPN_Postcode", postcode));

                ResetByteArray(ref temp);
                status = MyKad_SDK.JPN_City(temp);
                if (status != 0)
                {
                    return(FpReturn.ErrorJPN_City);
                }
                strList.Add(string.Format("{0}={1}", "JPN_City", ConvertByteToString(temp).TrimEnd('\0')));

                status = MyKad_SDK.JPN_State(temp);
                if (status != 0)
                {
                    return(FpReturn.ErrorJPN_State);
                }
                strList.Add(string.Format("{0}={1}", "JPN_State", ConvertByteToString(temp).TrimEnd('\0')));

                ResetByteArray(ref temp);
                status = MyKad_SDK.JPN_Citizenship(temp);
                if (status != 0)
                {
                    return(FpReturn.ErrorJPN_Citizenship);
                }
                strList.Add(string.Format("{0}={1}", "JPN_Citizenship", ConvertByteToString(temp).TrimEnd('\0')));

                ResetByteArray(ref temp);
                status = MyKad_SDK.JPN_Religion(temp);
                if (status != 0)
                {
                    return(FpReturn.ErrorJPN_Religion);
                }
                strList.Add(string.Format("{0}={1}", "JPN_Religion", ConvertByteToString(temp).TrimEnd('\0')));

                ResetByteArray(ref temp);
                status = MyKad_SDK.JPN_EastMsian(temp);
                if (status != 0)
                {
                    return(FpReturn.ErrorJPN_EastMsian);
                }
                strList.Add(string.Format("{0}={1}", "JPN_EastMsian", ConvertByteToString(temp).TrimEnd('\0')));

                ResetByteArray(ref temp);
                status = MyKad_SDK.JPN_Gender(temp);
                if (status != 0)
                {
                    return(FpReturn.ErrorJPN_Gender);
                }
                strList.Add(string.Format("{0}={1}", "JPN_Gender", ConvertByteToString(temp).TrimEnd('\0')));

                if (!SaveInfoFile(strList, _infoPath))
                {
                    return(FpReturn.ErrorSaveInfoFile);
                }

                byte[] photo = new byte[4000];
                status = MyKad_SDK.JPN_Photo(photo);
                if (0 == status)
                {
                    MemoryStream memstr = new MemoryStream(photo);
                    img = new Bitmap(memstr);
                    //pictureBoxPhoto.Image = new Bitmap(memstr);
                }

                //if (0 == status)
                //{
                fp1    = new byte[598];
                status = MyKad_SDK._JPN_Thumb1(fp1);
                if (status != 0)
                {
                    return(FpReturn.ErrorJPN_Thumb1);
                }

                if (!SaveTemplateFile(fp1, fp1.Length, _thumbPath1))
                {
                    return(FpReturn.ErrorSaveTemplateFile);
                }

                //if (0 == status)
                //{
                fp2    = new byte[598];
                status = MyKad_SDK._JPN_Thumb2(fp2);
                if (status != 0)
                {
                    return(FpReturn.ErrorJPN_Thumb2);
                }

                if (!SaveTemplateFile(fp2, fp2.Length, _thumbPath2))
                {
                    return(FpReturn.ErrorSaveTemplateFile);
                }
                //    APIname = "JPN_Thumb2";
                //    if (0 == status)
                //    {
                //        //Thumb 2 template will store in thumb2 byte array
                //        //Normally Thumb 2 is left thumb
                //    }
                //}
                return(FpReturn.Success);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(null, ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
            finally
            {
                //if (0 != status)
                //    ErrorHandle(APIname, status, state);

                //btnReadMyKad.Enabled = true;
            }

            return(FpReturn.ErrorUnknown);
        }