Exemple #1
0
        public byte[] CardSendCommand(byte[] cmd)
        {
            if (ShowLog != null)
            {
                ShowLog("------------------------------\r\n");
                ApduCommand msg = new ApduCommand(cmd);

                if (msg.CmdNote.Trim().StartsWith("建立文件"))
                {
                    CPUFileType cpy = (CPUFileType)(msg.Data[0]);
                    msg.CmdNote += "类型" + cpy.ToString() + "    ";
                }
                string log = $"发送原始命令:{BitConverter.ToString(cmd)} \r\n" + msg.ToString() + "\r\n";



                ShowLog(log);
            }

            byte[] result = this.carder.SendCommand(cmd);

            if (ShowLog != null)
            {
                ApduMsg apduMsg = ApduMsgHelper.GetApduMsg(result);

                string msg = "状态:{0}  信息:{1} 结果:{2} \r\n";

                msg = string.Format(msg, apduMsg.Status, apduMsg.Msg, BitConverter.ToString(apduMsg.ResponseData));

                string log = "接收: " + msg;
                ShowLog(log);
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// 初始化,转换命令为ApduCommad
        /// </summary>
        /// <param name="cmdData"></param>
        public ApduCommand(byte[] cmdData)
        {
            //命令长度最少4字节
            if (cmdData.Length < 4)
            {
                Msg    = "命令长度小于4";
                IsPass = false;
                return;
            }



            //设置固定字段的值
            CLA = cmdData[0];
            INS = cmdData[1];
            P1  = cmdData[2];
            P2  = cmdData[3];


            CmdNote = ApduMsgHelper.GetSendCmdNote(CLA, INS);

            if (cmdData.Length == 5)
            {
                //只有5字节,则最后一个是LE..
                LE = cmdData[4];
                //LE不能大于136
                if (LE > 136)
                {
                    CmdNote += $"-LE长度超过限制{LE}-";
                }
                return;
            }


            if (cmdData.Length > 4)
            {
                //如果有LC,则判断Data的长度是否符合LC
                if (cmdData[4] > 0)
                {
                    LC = cmdData[4];

                    if (cmdData.Length < LC + 4)
                    {
                        Msg    = "LC 长度错误:" + LC;
                        IsPass = false;
                        return;
                    }
                    //取出Data并赋值
                    Data = new byte[LC];
                    Array.Copy(cmdData, 5, Data, 0, LC);
                }
                else
                {
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// 获取apduMsg对象
 /// </summary>
 /// <param name="ApduMsg"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static ApduMsg GetApduByData(byte[] ResponseData)
 {
     return(ApduMsgHelper.GetApduMsg(ResponseData));
 }