Ejemplo n.º 1
0
        public void SslLikeConversation()
        {
            RsaAesEncryptor alice = new RsaAesEncryptor();
            RsaAesDecryptor bob   = new RsaAesDecryptor();

            alice.EncryptFile(bob, TestFile, TestFileEncrypted);
            bob.DecryptFile(alice, TestFileEncrypted, TestFileDecrypted);

            // assert files
            Hashing h = new Hashing();

            byte[] b     = h.Sha512HashFile(TestFile);
            string hash1 = HexHelper.ByteArrayToHexString(b);

            Console.WriteLine(hash1);

            b = h.Sha512HashFile(TestFileEncrypted);
            string hash2 = HexHelper.ByteArrayToHexString(b);

            Console.WriteLine("[{0}] bytes {1}, bits {2}", hash2, hash2.Length, hash2.Length * 4);

            b = h.Sha512HashFile(TestFileDecrypted);
            string hash3 = HexHelper.ByteArrayToHexString(b);

            Console.WriteLine(hash3);

            Assert.AreEqual(hash1, hash3);
            Assert.AreNotEqual(hash1, hash2);
        }
Ejemplo n.º 2
0
        private void lbMIHostInfoAddrSync_Click(object sender, RoutedEventArgs e)
        {
            TreeHostInfo thi = (TreeHostInfo)tvHostLightInfo.SelectedItem;
            int          id;

            if (!string.IsNullOrEmpty(thi.HostInfo.Addr) && int.TryParse(thi.HostInfo.Addr, out id))
            {
                CMDSend cmdSend = new CMDSend();
                cmdSend.GUID        = Guid.NewGuid().ToString();
                cmdSend.Addr        = thi.HostInfo.Addr;
                cmdSend.Content     = HexHelper.ByteArrayToHexString(ProtocolManage.LightGPRSProtocol.AddrSyncCMD(id));
                cmdSend.ContentType = (int)CMDType.InterSetCMD;
                cmdSend.CreateDate  = DateTime.Now;
                cmdSend.ID          = thi.HostInfo.IDID;
                cmdSend.UpdateDate  = cmdSend.CreateDate;
                cmdSend.State       = (int)CMDState.NO;
                SyncDataDlg sdd = new SyncDataDlg("同步地址", thi.HostInfo.Name, cmdSend);
                sdd.ShowDialog();
            }
        }
Ejemplo n.º 3
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            bool exit = false;

            e.Result = false;
            CMDRevBLL cmdRevBLL = new CMDRevBLL();

            CMDSend cmdSend = new CMDSend();
            int     id;

            if (!string.IsNullOrEmpty(hostInfo.Addr) && int.TryParse(hostInfo.Addr, out id))
            {
                cmdSend.GUID        = Guid.NewGuid().ToString();
                cmdSend.Addr        = hostInfo.Addr;
                cmdSend.Content     = HexHelper.ByteArrayToHexString(ProtocolManage.LightGPRSProtocol.IntervalSyncCMD(id, start, len, count));
                cmdSend.ContentType = (int)CMDType.InterSetCMD;
                cmdSend.CreateDate  = DateTime.Now;
                cmdSend.ID          = hostInfo.IDID;
                cmdSend.UpdateDate  = cmdSend.CreateDate;
                cmdSend.State       = (int)CMDState.NO;

                Debug.WriteLine("开始往数据库中写入命令");
                {
                    if (new CMDSendBLL().Add(cmdSend))
                    {
                        timeout = defaultTimeout;
                        Debug.WriteLine("写入服务器命令成功");
                    }
                    else
                    {
                        return;
                    }
                }
                while (true)
                {
                    if (bw.CancellationPending == true || timeout == 0)
                    {
                        e.Cancel = true;
                        break;
                    }
                    switch ((CMDType)(cmdSend.ContentType))
                    {
                    case CMDType.InterSetCMD:
                    {
                        try
                        {
                            Debug.WriteLine("查询服务器返回的值");
                            List <CMDRev> result = cmdRevBLL.GetModelByIDAndTime(cmdSend.ID, (byte)CMDType.InterSetRev, -60, (int)CMDState.NO);
                            if (result != null && result.Count > 0)
                            {
                                string[] strContent = result[0].Content.Split(' ');
                                if (strContent.Length == 3)
                                {
                                    if (int.Parse(strContent[2]) == 1)
                                    {
                                        Debug.WriteLine("命令执行成功");
                                        // 命令成功
                                        bw.ReportProgress(100, true);
                                        exit     = true;
                                        e.Result = true;
                                        Thread.Sleep(2000);
                                    }
                                    else
                                    {
                                        Debug.WriteLine("命令执行失败");
                                        // 命令失败
                                        bw.ReportProgress(99, false);
                                        exit = true;
                                    }
                                    result[0].State      = (int)CMDState.Yes;
                                    result[0].UpdateDate = DateTime.Now;
                                    cmdRevBLL.Update(result[0]);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                    }
                    break;

                    default:
                        break;
                    }
                    if (exit == true)
                    {
                        break;
                    }
                    timeout--;
                    bw.ReportProgress(timeout, null);
                    Thread.Sleep(1000);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 发送命令
        /// </summary>
        /// <returns>Int</returns>
        public JsonResult GetHostRealStateCmdPost()
        {
            /*
             * result :
             * 0:参数错误
             * 1:主机未设置地址
             * 2:写数据库失败
             * 3:写成功
             */
            BLL.tHostInfo   bllhost = new BLL.tHostInfo();
            Model.tHostInfo modhost = new Model.tHostInfo();
            BLL.tCMDSends   bllsend = new BLL.tCMDSends();
            Model.tCMDSends modsend = new Model.tCMDSends();
            byte[]          bt1     = null;
            int             result  = 0;

            if (!string.IsNullOrWhiteSpace(Request.QueryString["sGuid"]))
            {
                Model.tHostInfo dt2 = bllhost.GetModel(Request.QueryString["sGuid"]);
                if (dt2 != null)
                {
                    if (!string.IsNullOrWhiteSpace(dt2.sID_Addr))
                    {
                        try
                        {
                            byte[] a = new byte[2];
                            a[0] = (byte)(int.Parse(dt2.sID_Addr) >> 8);
                            a[1] = (byte)(int.Parse(dt2.sID_Addr));
                            bt1  = LightGPRSProtocol.GetStringFor0x68((byte)CMDType.GetHostAllInfoCMD, a);
                            if (bt1 != null)
                            {
                                modsend.dCreateDate  = DateTime.Now;
                                modsend.dUpdateTime  = DateTime.Now;
                                modsend.sGUID        = Guid.NewGuid().ToString();
                                modsend.iContentType = (int)CMDType.GetHostAllInfoCMD;
                                string str = HexHelper.ByteArrayToHexString(bt1);
                                modsend.sContent = str;
                                modsend.iState   = (int)CMDState.NO;
                                if (dt2.iIDType != null)
                                {
                                    modsend.iHostIDType = dt2.iIDType;
                                }
                                if (dt2.iIDType != null)
                                {
                                    modsend.iHostIDType = dt2.iIDType;
                                }
                                if (!string.IsNullOrWhiteSpace(dt2.sID_Addr))
                                {
                                    modsend.sHostIDAddr = dt2.sID_Addr;
                                }
                                if (!string.IsNullOrWhiteSpace(dt2.sID_ID))
                                {
                                    modsend.sHostIDID = dt2.sID_ID;
                                }
                                if (!string.IsNullOrWhiteSpace(dt2.sID_IP))
                                {
                                    modsend.sHostIDIP = dt2.sID_IP;
                                }
                                if (!string.IsNullOrWhiteSpace(dt2.sID_MAC))
                                {
                                    modsend.sHostIDMAC = dt2.sID_MAC;
                                }
                                if (!string.IsNullOrWhiteSpace(dt2.sID_SIM))
                                {
                                    modsend.sHostIDSIM = dt2.sID_SIM;
                                }
                                if (bllsend.Add(modsend) == true)
                                {
                                    result = 3;
                                    return(Json(result));
                                }
                                else
                                {
                                    result = 2;
                                    return(Json(result));
                                }
                            }
                            else
                            {
                                result = 2;
                                return(Json(result));
                            }
                        }
                        catch (Exception)
                        {
                            result = 2;
                            return(Json(result));
                        }
                    }
                    else
                    {
                        result = 1;
                        return(Json(result));
                    }
                }
                else
                {
                    result = 0;
                    return(Json(result));
                }
            }
            else
            {
                result = 0;
                return(Json(result));
            }
        }