Esempio n. 1
0
        /// <summary>
        ///  客户端重新连接
        /// </summary>
        /// <returns></returns>
        public override Task OnReconnected()
        {
            string mac = MacUtils.GetClientMAC(HttpContext.Current.Request);
            string id  = Context.ConnectionId;

            Debug.WriteLine($" Reconnected : mac = {mac} ; id = {id}");
            return(base.OnReconnected());
        }
Esempio n. 2
0
        /// <summary>
        /// 客户端连接
        /// </summary>
        public void Connection()
        {
            string mac = MacUtils.GetClientMAC(HttpContext.Current.Request);

            Cache.DeleteCache(mac);
            string id = Context.ConnectionId;

            Debug.WriteLine($" Connected : mac = {mac} ; id = {id}");
            //将客户端websocket Id存起来
            Cache.SetCache(mac, id);
            Clients.Client(id).Reciver(mac, id);
        }
Esempio n. 3
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));//ConfigurationManager.AppSettings["WTMacKey"]

            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);
        }
Esempio n. 4
0
        /// <summary>
        /// 换算PIN
        /// </summary>
        /// <param name="pwd">用户输入的密码</param>
        /// <param name="cardNo">获取的ic卡卡号</param>
        /// <returns></returns>
        public static string getPin(string pwd, string cardNo)
        {
            string result = string.Empty;
            int    len    = cardNo.Length - 4;
            string pwdLen = pwd.Length + "";

            if (pwdLen.Length == 1)
            {
                pwd = "0" + pwdLen + pwd;
            }
            string cardNoCover = "";

            if (len < 12)
            {
                cardNo = cardNo.Substring(4, len);
                for (int i = 0; i < 12 - len; i++)
                {
                    cardNoCover += "f";
                }
            }
            else
            {
                cardNo = cardNo.Substring(3, 12);
            }
            cardNo = cardNoCover + cardNo;
            for (int i = 0; i < 32; i++)
            {
                if (cardNo.Length < 32)
                {
                    cardNo = "0" + cardNo;
                }
                if (pwd.Length < 32)
                {
                    pwd = pwd + "f";
                }
            }

            string orx = MacUtils.xOrString(cardNo, pwd);

            //Console.WriteLine("orx="+ orx);
            result = BCDUtil.byteArrToString(CSm4.EncriptB(BCDUtil.ToByteArray(pinKey), BCDUtil.ToByteArray(orx)));//BCDUtil.ToByteArray(ConfigurationManager.AppSettings["WTPinKey"])
            // Console.WriteLine("result="+ result);
            Console.WriteLine(result.ToUpper());
            return(result.ToUpper());
        }