Exemple #1
0
        public static SubSelect GetSubData(byte[] data, HandshakeResponse handresponse)
        {
            SubSelect subdata = new SubSelect();

            if (!VerificationTools.HashCheck(data.ToList()))
            {
                return(null);
            }
            var decr = Cryptogram.Decrypt(data, handresponse);

            return(AnalysisSubSelect(decr));
        }
        /// <summary>
        /// 握手协议可能会抛出异常
        /// </summary>
        /// <returns></returns>
        public bool Handshake()
        {
            Byte[]      TxData = { };
            List <Byte> l      = new List <byte>();

            l.Add(0xAA);
            l.Add(0x10);
            Random random = new Random();

            for (int i = 0; i < 79; i++)
            {
                l.Add(Convert.ToByte(random.Next(0, 255)));
            }
            var last = VerificationTools.HashCalc(l);

            l.Add(Convert.ToByte(last));
            TxData = l.ToArray();
            TryWrite(TxData, 0, 82);
            return(true);
        }
Exemple #3
0
        public Byte[] GetFinalArray()
        {
            List <Byte> listFinalBody = new List <byte>();

            listFinalBody.Add(Convert.ToByte((machineAddress & 0xFF000000) >> 24));
            listFinalBody.Add(Convert.ToByte((machineAddress & 0xFF0000) >> 16));
            listFinalBody.Add(Convert.ToByte((machineAddress & 0xFF00) >> 8));
            listFinalBody.Add(Convert.ToByte(machineAddress & 0xFF));

            listFinalBody.Add(Convert.ToByte(number));

            listFinalBody.Add(Convert.ToByte(dotPwoer));

            listFinalBody.Add(Convert.ToByte((request & 0xFF00000000000000) >> 56));
            listFinalBody.Add(Convert.ToByte((request & 0xFF000000000000) >> 48));
            listFinalBody.Add(Convert.ToByte((request & 0xFF0000000000) >> 40));
            listFinalBody.Add(Convert.ToByte((request & 0xFF00000000) >> 32));
            listFinalBody.Add(Convert.ToByte((request & 0xFF000000) >> 24));
            listFinalBody.Add(Convert.ToByte((request & 0xFF0000) >> 16));
            listFinalBody.Add(Convert.ToByte((request & 0xFF00) >> 8));
            listFinalBody.Add(Convert.ToByte(request & 0xFF));

            listFinalBody.Add(share1.GetShare1Byte(GetShare1Enum()));
            listFinalBody.Add(share2.GetShare2Byte());


            List <Byte> listFinal = new List <byte>();

            listFinal.Add(Convert.ToByte(head));

            listFinal.Add(Convert.ToByte(dataBelong));

            listFinal.Add(Convert.ToByte((handshakeSecretKey & 0xFF00) >> 8));
            listFinal.Add(Convert.ToByte(handshakeSecretKey & 0xFF));
            listFinal.AddRange(Cryptogram.Encryption(listFinalBody, listFinal[3], listFinal[2]));

            listFinal.Add(Convert.ToByte(VerificationTools.HashCalc(listFinal)));

            return(listFinal.ToArray());
        }
        public static HandshakeResponse AnalysisHandshake(Int32[] text)
        {
            HandshakeResponse handshake = new HandshakeResponse();

            if (text == null || text.Count() != 82)
            {
                throw new Exception("握手异常");
            }
            //TODO 散列校验

            List <Int32> listtext = text.ToList();

            if (!VerificationTools.HandshakeHeadVerification(listtext) || !VerificationTools.HashCheck(listtext))
            {
                throw new Exception("握手异常-握手返回值异常");
            }
            handshake.Channel = listtext[2];
            int highSecretKey = listtext[22] << 8;
            int lowSecretKey  = listtext[23];

            handshake.SecretKey = highSecretKey + lowSecretKey;
            long fisrtAddress  = ((long)listtext[24]) << 24;
            long secondAddress = ((long)listtext[25]) << 16;
            long thirdAddress  = ((long)listtext[26]) << 8;
            long fourthAddress = ((long)listtext[27]);

            handshake.Address = fisrtAddress + secondAddress + thirdAddress + fourthAddress;
            List <Byte> remorklist = new List <Byte>();

            for (int i = 34; i < 79; i++)
            {
                remorklist.Add((Byte)listtext[i]);
            }
            handshake.Remark = Encoding.GetEncoding("GBK").GetString(remorklist.ToArray()).Replace("\0", "");
            return(handshake);
        }
 public void AnalysisHandshakeProtocol()
 {
     int[] TxData = { 170, 17, 1, 1, 1, 1, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 2, 9, 0, 0, 0, 2, 0, 255, 0, 255, 0, 255, 177, 177, 190, 169, 201, 207, 206, 170, 190, 253, 179, 207, 191, 198, 188, 188, 211, 208, 207, 222, 185, 171, 203, 190, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 193 };
     //var k=HandshakeTools.AnalysisHandshake(TxData);
     var kk = VerificationTools.HashCheck(TxData.ToList());
 }