Example #1
0
        private void OnSendClick(object sender, RoutedEventArgs e)
        {
            string sendText = textAPDU.Text;

            string[] sendArray = sendText.Split('-');

            if (sendArray.Length < 4)
            {
                AddLog("Invalid Command");
                AddLog("-------");
                return;
            }

            byte[] data = new byte[sendArray.Length];

            for (int i = 0; i < sendArray.Length; i++)
            {
                data[i] = Convert.ToByte(sendArray[i], 16);
            }

            string datastring = BitConverter.ToString(data);

            AddLog("Send APDU Command:" + datastring);

            ApduCommand command = new ApduCommand(data);

            controller.SendAPDUCommand(readerList[0], command);

            if ((bool)checkResetAPDUC.IsChecked)
            {
                textAPDU.Text = "";
            }
        }
Example #2
0
        private ApduResponse SendCommand(ApduCommand apduCommand)
        {
            ApduResponse response = cardInterface.SendCommand(apduCommand);

            if (response is DesfireResponse)
            {
                return(response);
            }

            throw new DesFireException("Error returned from card");
        }
Example #3
0
        private void button15_Click(object sender, EventArgs e)
        {
            try
            {
                byte[] data = CPUCardHelper.ConverToBytes(txtCMd.Text);

                ApduCommand cmd = new ApduCommand(data);
                txtLog.AppendText("解析命令:" + cmd.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #4
0
        public override byte[] ProcessCommandApdu(byte[] commandApdu, Bundle extras)
        {
            try
            {
                ApduCommand command = new ApduCommand();
                command.Deserialize(commandApdu);
                Logger.Log(command.ToString());

                switch (command.INS)
                {
                case (byte)EMVInstructionEnum.Select:
                    //PPSE or applet select
                    if (Formatting.ByteArrayToHexString(command.CommandData) == PPSE_NAME)
                    {
                        return(ppseSelectResponse);
                    }
                    else if (Formatting.ByteArrayToHexString(command.CommandData) == APPLET_AID)
                    {
                        return(appletSelectResponse);
                    }
                    else
                    {
                        return(BitConverter.GetBytes((int)ISO7816ReturnCodes.SW_INS_NOT_SUPPORTED));
                    }

                case (byte)EMVInstructionEnum.GetProcessingOptions:
                    return(DoGPO(commandApdu));


                default:
                    return(BitConverter.GetBytes((int)ISO7816ReturnCodes.SW_INS_NOT_SUPPORTED));
                }
            }
            catch (Exception ex)
            {
                return(BitConverter.GetBytes((int)ISO7816ReturnCodes.SW_INS_NOT_SUPPORTED));
            }
        }
Example #5
0
        /// <summary>
        ///     Extension method to SmartCardConnection class similar to Transmit asyc method, however it accepts PCSC SDK
        ///     commands.
        /// </summary>
        /// <param name="apduCommand">
        ///     APDU command object to send to the ICC
        /// </param>
        /// <param name="connection">
        ///     SmartCardConnection object
        /// </param>
        /// <returns>APDU response object of type defined by the APDU command object</returns>
        public static async Task <Iso7816.ApduResponse> TransceiveAsync(this SmartCardConnection connection, ApduCommand apduCommand)
        {
            var apduRes = (Iso7816.ApduResponse)Activator.CreateInstance(apduCommand.ApduResponseType);

            if (!IsFirstConnection)
            {
                await Task.Delay(500);
            }

            var responseBuf = connection.Transceive(apduCommand.GetBuffer());

            apduRes.ExtractResponse(responseBuf.ToArray());


            return(apduRes);
        }
Example #6
0
        /// <summary>
        ///     Extension method to SmartCardConnection class similar to Transmit asyc method, however it accepts PCSC SDK
        ///     commands.
        /// </summary>
        /// <param name="apduCommand">
        ///     APDU command object to send to the ICC
        /// </param>
        /// <param name="connection">
        ///     SmartCardConnection object
        /// </param>
        /// <returns>APDU response object of type defined by the APDU command object</returns>
        public static async Task <Iso7816.ApduResponse> TransceiveAsync(this SmartCardConnection connection, ApduCommand apduCommand)
        {
            var apduRes = (Iso7816.ApduResponse)Activator.CreateInstance(apduCommand.ApduResponseType);

            var responseBuf = await connection.TransmitAsync(apduCommand.GetBuffer().AsBuffer());

            apduRes.ExtractResponse(responseBuf.ToArray());

            return(apduRes);
        }
Example #7
0
        protected override async Task <ApduResponse> TransceiveAsync(ApduCommand apduCommand)
        {
            await initialization;

            return(await((connection?.TransceiveAsync(apduCommand)) ?? completed));
        }
Example #8
0
 protected abstract Task <ApduResponse> TransceiveAsync(ApduCommand apduCommand);