Exemple #1
0
        /// <summary>
        /// Read the smart card and authenticate it using EMVCO rules
        /// </summary>
        /// <param name="readerName"></param>
        /// <returns>AltsInfo Authenticated True or false</returns>
        private AltsInfo Authenticate(string readerName)
        {
            AltsInfo ok = new AltsInfo();

            try
            {
                SmartCard        sa   = new SmartCard(readerName);
                var              res  = sa.GetAIDs(true);
                SmartApplication sapp = sa.Applications[0];
                sapp.SelectApplication();
                sapp.GetProcessingOptions();
                sapp.ReadRecords();


                OfflineAuth oa = new OfflineAuth(sapp);

                string cardNumber = sapp.GetTagValue(EmvConstants.ResponceType.ReaderRecord, "5A");
                string expdate    = sapp.GetTagValue(EmvConstants.ResponceType.ReaderRecord, "5F25");
                ///Keep the hash data of cardnumber and expiryDate
                string token = HashData(cardNumber + expdate, oa.ICC_KEY_HASH);

                ok.Authenticated = !string.IsNullOrEmpty(token);
                ok.AuthDeviceId  = token;
            }
            catch (Exception ex)
            {
                ok.Authenticated = false;
                ok.AuthDeviceId  = ex.Message;
            }
            return(ok);
        }
Exemple #2
0
        private void TrustDevice(string readerName)
        {
            SmartCard        sa   = new SmartCard(readerName);
            var              res  = sa.GetAIDs(true);
            SmartApplication sapp = sa.Applications[0];

            sapp.SelectApplication();
            sapp.GetProcessingOptions();
            sapp.ReadRecords();
            OfflineAuth oa = new OfflineAuth(sapp);

            string cardNumber = sapp.GetTagValue(EmvConstants.ResponceType.ReaderRecord, "5A");
            string expdate    = sapp.GetTagValue(EmvConstants.ResponceType.ReaderRecord, "5F25");
            ///Keep the hash data of cardnumber and expiryDate
            string token = HashData(cardNumber + expdate, oa.ICC_KEY_HASH);

            AltsInfo ok = new AltsInfo()
            {
                AuthDeviceId = token, Authenticated = !string.IsNullOrEmpty(token)
            };

            if (ok.Authenticated)
            {
                TrustedDevice = ok;
            }
        }