Exemplo n.º 1
0
 public ResultData analysisBit63(byte[] dataStr, ResultData rd)
 {
     varAsciiStr(dataStr, rd, 2);
     PosProtocol.rightBcdComplete(rd, 3);
     rd.name = "自定义域";
     return(new ResultData(rd));
 }
Exemplo n.º 2
0
        public ResultData analysisBit58(byte[] dataStr, ResultData rd)
        {
            varRightBcd(dataStr, rd, 2);
            PosProtocol.rightBcdComplete(rd, 3);
            rd.name = "电子钱包标准的交易信息";

            return(new ResultData(rd));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 可变长度ascii
        /// </summary>
        /// <param name="dataStr"></param>
        /// <param name="rd"></param>
        /// <param name="len"></param>
        private void varAsciiStr(byte[] dataStr, ResultData rd, int len)
        {
            int datalength = Convert.ToInt32(PosProtocol.bcd2Str(PosProtocol.subbyte(dataStr, rd.pos, len)));

            rd.pos += len;
            //如果长度大于 已知位数,则截取掉最后多余的位数
            string data = PosProtocol.toAsciiStr(PosProtocol.subbyte(dataStr, rd.pos, datalength));

            rd.pos  += datalength;
            rd.value = data;
        }
Exemplo n.º 4
0
        public void varAnalysisBit(byte[] dataStr, ResultData rd, int len)
        {
            int datalength = Convert.ToInt32(PosProtocol.bcd2Str(PosProtocol.subbyte(dataStr, rd.pos, len)));

            rd.pos += len;
            //如果长度大于 已知位数,则截取掉最后多余的位数
            string data = PosProtocol.bytesToHexString(PosProtocol.subbyte(dataStr, rd.pos, datalength));

            rd.pos  += datalength;
            rd.value = data;
        }
Exemplo n.º 5
0
        /// <summary>
        /// 可变长度BCD
        /// </summary>
        /// <param name="rd"></param>
        private void varRightBcd(byte[] dataStr, ResultData rd, int len)
        {
            int cardNolength = Convert.ToInt32(PosProtocol.bcd2Str(PosProtocol.subbyte(dataStr, rd.pos, len)));

            rd.pos += len;
            int bcdcardNolength = PosProtocol.bcdlength(cardNolength);
            //如果长度大于 已知位数,则截取掉最后多余的位数
            string cardNo = sub(PosProtocol.bcd2Str(PosProtocol.subbyte(dataStr, rd.pos, bcdcardNolength)), cardNolength);

            rd.pos  += bcdcardNolength;
            rd.value = cardNo;
        }
Exemplo n.º 6
0
        public new ResultData analysisBit44(byte[] dataStr, ResultData rd)
        {
            int len        = 1;
            int datalength = Convert.ToInt32(PosProtocol.bcd2Str(PosProtocol.subbyte(dataStr, rd.pos, len)));

            rd.pos += len;
            //如果长度大于 已知位数,则截取掉最后多余的位数
            string data = PosProtocol.bytesToHexString(PosProtocol.subbyte(dataStr, rd.pos, datalength));

            rd.pos  += datalength;
            rd.value = data;
            return(new ResultData(rd));
        }
Exemplo n.º 7
0
        public new ResultData analysisBit57(byte[] dataStr, ResultData rd)
        {
            int len        = 2;
            int datalength = Convert.ToInt32(PosProtocol.bcd2Str(PosProtocol.subbyte(dataStr, rd.pos, len)));

            rd.pos += len;
            //如果长度大于 已知位数,则截取掉最后多余的位数
            string data = PosProtocol.toAsciiStr(PosProtocol.subbyte(dataStr, rd.pos, datalength));

            rd.pos  += datalength;
            rd.value = datalength + "," + data;
            rd.name  = "analysisBit57";
            return(new ResultData(rd));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 计算mac 公共类
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static byte[] calculateMac(Dictionary <int, string> data, string msgType)
        {
            //计算MAC用到的数据
            byte[] countMacData = EncryptWT.countMacData(msgType, EncryptWT.encryptLKL(data, null));
            Console.WriteLine(BCDUtil.byteArrToString(countMacData));
            string str = MacUtils.CSMMAC(mackey, BCDUtil.byteArrToString(countMacData));

            Console.WriteLine("bcd2Str:" + PosProtocol.bcd2Str(System.Text.Encoding.Default.GetBytes(str.Substring(0, 8))));
            //MAC转byte[]
            String strMac = PosProtocol.bcd2Str(System.Text.Encoding.Default.GetBytes(str.Substring(0, 8).ToUpper()));

            byte[] macByte = BCDUtil.ToByteArray(strMac);
            return(macByte);
        }
Exemplo n.º 9
0
        public ResultData analysisBit62(byte[] dataStr, ResultData rd)
        {
            int len        = 2;
            int datalength = Convert.ToInt32(PosProtocol.bcd2Str(PosProtocol.subbyte(dataStr, rd.pos, len)));

            rd.pos += len;
            //如果长度大于 已知位数,则截取掉最后多余的位数
            string data = BCDUtil.byteArrToString(PosProtocol.subbyte(dataStr, rd.pos, datalength));

            rd.pos  += datalength;
            rd.value = data;
            rd.name  = "自定义域终端密钥";
            return(new ResultData(rd));
        }
Exemplo n.º 10
0
        /// <summary>
        /// 验证数据是否通过验证
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        static string validateKey(string data, string key)
        {
            string validata = data.Substring(data.Length - 8, 8).ToUpper();

            byte[] sources   = BCDUtil.HexStrToByteArray(data.Substring(0, 32));
            byte[] desKeys   = BCDUtil.HexStrToByteArray(key);
            byte[] encSource = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            byte[] encKeys   = CSm4.DecriptB(desKeys, sources);
            if (PosProtocol.bytesToHexString(CSm4.EncriptB(encKeys, encSource)).Substring(0, 8).Equals(validata))
            {
                Console.WriteLine("密钥验证通过返回灌输密钥!!!!");
                return(PosProtocol.bytesToHexString(encKeys));
            }
            return("");
        }
Exemplo n.º 11
0
        public new ResultData analysisBit58(byte[] dataStr, ResultData rd)
        {
            int len          = 3;
            int cardNolength = Convert.ToInt32(PosProtocol.toAsciiStr(PosProtocol.subbyte(dataStr, rd.pos, len)));

            rd.pos += len;

            //如果长度大于 已知位数,则截取掉最后多余的位数
            string cardNo = PosProtocol.bcd2Str(PosProtocol.subbyte(dataStr, rd.pos, cardNolength));

            // cardNo = Convert.ToString(Convert.ToInt64(cardNo), 16);
            rd.pos  += cardNolength;
            rd.value = cardNo;
            rd.name  = "电子钱包标准的交易信息";
            return(new ResultData(rd));
        }
Exemplo n.º 12
0
        public override Dictionary <string, ResultData> analysis(byte[] b)
        {
            try
            {
                Dictionary <string, ResultData> list = new Dictionary <string, ResultData>();

                ResultData rd = new ResultData(2);

                list.Add("header", this.analysisHeader(b, rd));
                list.Add("tpdu", this.analysisTPDU(b, rd));
                list.Add("msgType", this.analysisMsgType(b, rd));
                Console.Write(rd.value);
                ResultData rse    = this.analysisBitMap(b, rd);
                Int64      bitmap = Convert.ToInt64(rse.value, 16);
                list.Add("map", rse);
                string _bitmap = PosProtocol.leftpad(PosProtocol.ToBinaryString(bitmap));
                Console.WriteLine("\n" + _bitmap);
                for (int i = 0; i < _bitmap.Length; i++)
                {
                    if (_bitmap.Substring(i, 1) == "1")
                    {
                        var    method = this.GetType().GetMethod("analysisBit" + (i + 1));
                        object obj    = new object();
                        obj = method.Invoke(this, new Object[] { b, rd });


                        if (obj != null)
                        {
                            ResultData e = (ResultData)obj;
                            // Console.WriteLine(method.Name + ":" + e.value + "\n");
                            list.Add("" + (i + 1), e);
                        }
                    }
                    //method.Invoke(instance, null);
                    //TODO
                }
                return(list);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// 获取报头
 /// </summary>
 /// <param name="dataStr"></param>
 /// <param name="rd"></param>
 /// <returns></returns>
 public override ResultData analysisHeader(byte[] dataStr, ResultData rd)
 {
     rd.value = Convert.ToInt64(PosProtocol.bytesToHexString(PosProtocol.subbyte(dataStr, 0, rd.pos)), 16).ToString();
     rd.name  = "Header";
     return(new ResultData(rd));
 }
Exemplo n.º 14
0
 public override void analysisBit(byte[] dataStr, ResultData rd, int len)
 {
     rd.value = PosProtocol.bytesToHexString(PosProtocol.subbyte(dataStr, rd.pos, len));
     rd.pos   = rd.pos + len;
 }
Exemplo n.º 15
0
 /// <summary>
 /// 获取报头
 /// </summary>
 /// <param name="dataStr"></param>
 /// <param name="rd"></param>
 /// <returns></returns>
 public override ResultData analysisHeader(byte[] dataStr, ResultData rd)
 {
     rd.value = PosProtocol.bcd2Str(PosProtocol.subbyte(dataStr, 0, rd.pos));
     rd.name  = "Header";
     return(new ResultData(rd));
 }
Exemplo n.º 16
0
 /// <summary>
 /// 固定长度ascii
 /// </summary>
 /// <param name="rd"></param>
 /// <param name="len"></param>
 /// <param name="dataStr"></param>
 private void fixedAsciiStr(ResultData rd, int len, byte[] dataStr)
 {
     rd.value = PosProtocol.toAsciiStr(PosProtocol.subbyte(dataStr, rd.pos, len));
     rd.pos   = rd.pos + len;
 }
Exemplo n.º 17
0
 /// <summary>
 /// 固定长度BCD解码
 /// </summary>
 /// <param name="rd"></param>
 public override void fixedRightBcd(ResultData rd, int len, byte[] dataStr)
 {
     rd.value = PosProtocol.bcd2Str(PosProtocol.subbyte(dataStr, rd.pos, len));
     rd.pos   = rd.pos + len;
 }