예제 #1
0
파일: TLVHelper.cs 프로젝트: ghbylmt/LsPay
        /// <summary>
        /// 根据tag获取tlv的值
        /// </summary>
        /// <param name="entities"></param>
        /// <param name="tag"></param>
        /// <returns></returns>
        public static TLVEntity GetValueByTag(List <TLVEntity> entities, string tag)
        {
            TLVEntity resultEntity = null;
            var       query        = entities.SingleOrDefault(e => CodeConvert.ToHexString(e.Tag).ToUpper() == tag);

            if (query == null)
            {
                foreach (var tlv in entities)
                {
                    if (tlv.SubTLVEntity != null)
                    {
                        TLVEntity result = GetValueByTag(tlv.SubTLVEntity, tag);

                        if (result != null && result.Length.Length > 0)
                        {
                            return(result);
                        }
                    }
                }
            }
            else
            {
                resultEntity = query;
            }
            return(resultEntity);
        }
예제 #2
0
        /// <summary>
        /// 转化成TL格式的字符串
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static List <string> ToTLStringList(byte[] bytes)
        {
            List <string> list = new List <string>();

            for (int i = 0; i < bytes.Length; i++)
            {
                List <byte> pdo = new List <byte>();
                if ((bytes[i] & 0xF) == 0xF)//判断tag是否占两位
                {
                    pdo.AddRange(new byte[] { bytes[i++], bytes[i++] });
                }
                else
                {
                    pdo.Add(bytes[i++]);
                }
                if ((bytes[i] & 0x80) == 0x80)//判读length是否占两位
                {
                    pdo.AddRange(new byte[] { bytes[i++], bytes[i++] });
                }
                else
                {
                    pdo.Add(bytes[i]);
                }
                list.Add(CodeConvert.ToHexString(pdo.ToArray()));
            }
            return(list);
        }