示例#1
0
        private void btnReg_Click(object sender, System.EventArgs e)
        {
            //读硬盘的序列号
            string       str_SerialNumber;
            HardDiskInfo hdd = AtapiDevice.GetHddInfo(0);             // 第一个硬盘

            str_SerialNumber = hdd.SerialNumber.ToString();

            DESEncryptor dese1 = new DESEncryptor();

            dese1.InputString = str_SerialNumber;
            dese1.EncryptKey  = "lhgynkm0";
            dese1.DesEncrypt();
            string miWen = dese1.OutString;

            dese1 = null;

            err = null;
            string strresult = cs.Register(miWen, SysInitial.LocalDeptName, SysInitial.CurOps.strOperName, out err);

            if (strresult == "connection")
            {
                MessageBox.Show("中心数据库连接失败,请检查网再重试!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                MessageBox.Show("注册申请已经发送至中心,请等待注册完成后,再重新启动系统!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                return;
            }
        }
示例#2
0
        internal static string EncryptTransString(string sValue)
        {
            DESEncryptor Mydes = new DESEncryptor();
            Mydes.EncryptKey = DateTime.Now.ToString("yyyy-MM-dd");
            Mydes.InputString = sValue;
            Mydes.DesEncrypt();

            return Mydes.OutString;
        }
示例#3
0
        internal static string EncryptTransString(string sValue)
        {
            DESEncryptor Mydes = new DESEncryptor();

            Mydes.EncryptKey  = DateTime.Now.ToString("yyyy-MM-dd");
            Mydes.InputString = sValue;
            Mydes.DesEncrypt();

            return(Mydes.OutString);
        }
示例#4
0
        internal static string EncryptStorageSring(string sKey, string sValue)
        {
            DESEncryptor Mydes = new DESEncryptor();
            Mydes.EncryptKey = sKey;
            Mydes.InputString = sValue;
            
            Mydes.DesEncrypt();

            return Mydes.OutString;
        }
示例#5
0
        /// <summary>
        /// 加密字符串
        /// </summary>
        /// <param name="strText">明文</param>
        /// <returns>密文</returns>
        public static string Encrypt(string strText)
        {
            //return Encrypt(strText,ENCRYPT_KEY + ENCRYPT_KEY);
            DESEncryptor dese = new DESEncryptor();

            dese.InputString = strText;
            dese.EncryptKey  = "cmsmyykx";
            dese.DesEncrypt();
            return(dese.OutString);
        }
示例#6
0
        static public void desConstring(string strpath)
        {
            string strdes = "";

            if (strDesFlag == "0")
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(strpath + @"\CMSM.exe.config");
                XmlNode keyNode = null;

                DESEncryptor dese = new DESEncryptor();
                dese.InputString = ConString;
                dese.EncryptKey  = "cmsmyykx";
                dese.DesEncrypt();
                strdes = dese.OutString;
                dese   = null;

                keyNode = doc.SelectSingleNode("/configuration/appSettings/add[@key='DBAMSCM']");
                keyNode.Attributes["value"].Value = strdes;

                dese             = new DESEncryptor();
                dese.InputString = CenterConString;
                dese.EncryptKey  = "cmsmyykx";
                dese.DesEncrypt();
                strdes = dese.OutString;
                dese   = null;

                keyNode = doc.SelectSingleNode("/configuration/appSettings/add[@key='DBAMSCMCenter']");
                keyNode.Attributes["value"].Value = strdes;

                keyNode = doc.SelectSingleNode("/configuration/appSettings/add[@key='DFLAG']");
                keyNode.Attributes["value"].Value = "1";
                doc.Save(strpath + @"\CMSM.exe.config");
            }
            else
            {
                DESEncryptor dese = new DESEncryptor();
                dese.InputString = ConString;
                dese.DecryptKey  = "cmsmyykx";
                dese.DesDecrypt();
                strdes = dese.OutString;
                dese   = null;

                ConString = strdes;

                dese             = new DESEncryptor();
                dese.InputString = CenterConString;
                dese.DecryptKey  = "cmsmyykx";
                dese.DesDecrypt();
                strdes = dese.OutString;
                dese   = null;

                CenterConString = strdes;
            }
        }
示例#7
0
        internal static string EncryptStorageSring(string sKey, string sValue)
        {
            DESEncryptor Mydes = new DESEncryptor();

            Mydes.EncryptKey  = sKey;
            Mydes.InputString = sValue;

            Mydes.DesEncrypt();

            return(Mydes.OutString);
        }
示例#8
0
        public void TestDesEncy()
        {
            DESEncryptor Mydes = new DESEncryptor();
            Mydes.EncryptKey = "Client2";
            Mydes.InputString = "1234567890";
            
            Mydes.DesEncrypt();

            string sResult = Mydes.OutString;

            Assert.IsNotNullOrEmpty(sResult);
        }
示例#9
0
        public void TestDesEncy()
        {
            DESEncryptor Mydes = new DESEncryptor();

            Mydes.EncryptKey  = "Client2";
            Mydes.InputString = "1234567890";

            Mydes.DesEncrypt();

            string sResult = Mydes.OutString;

            Assert.IsNotNullOrEmpty(sResult);
        }
示例#10
0
 /// <summary>
 /// 数据库初始化
 /// </summary>
 private void DBInit()
 {
     MongoHelper<User> helperUser = new MongoHelper<User>();
     if (helperUser.Count() == 0)
     {
         User user;
         user = new User();
         user.usercode = "admin";
         user.pwd = DESEncryptor.DesEncrypt("123456");
         user.email = "*****@*****.**";
         user.username = "******";
         helperUser.Insert(user);
     }
 }
示例#11
0
        public static string Encrypt(string inputString)
        {
            if (string.IsNullOrEmpty(inputString))
            {
                return(string.Empty);
            }

            var encryptor = new DESEncryptor
            {
                InputString = inputString,
                EncryptKey  = "TgQQk42O"
            };

            encryptor.DesEncrypt();
            return(encryptor.OutString);
        }
示例#12
0
        public static string EncodePassword(string password, EPasswordFormat passwordFormat, out string passwordSalt)
        {
            var retval = string.Empty;

            passwordSalt = string.Empty;

            if (passwordFormat == EPasswordFormat.Clear)
            {
                retval = password;
            }
            else if (passwordFormat == EPasswordFormat.Hashed)
            {
                passwordSalt = GenerateSalt();

                var src     = Encoding.Unicode.GetBytes(password);
                var buffer2 = Convert.FromBase64String(passwordSalt);
                var dst     = new byte[buffer2.Length + src.Length];
                Buffer.BlockCopy(buffer2, 0, dst, 0, buffer2.Length);
                Buffer.BlockCopy(src, 0, dst, buffer2.Length, src.Length);
                var algorithm = HashAlgorithm.Create("SHA1");
                if (algorithm == null)
                {
                    return(retval);
                }
                var inArray = algorithm.ComputeHash(dst);

                retval = Convert.ToBase64String(inArray);
            }
            else if (passwordFormat == EPasswordFormat.Encrypted)
            {
                passwordSalt = GenerateSalt();

                var encryptor = new DESEncryptor
                {
                    InputString = password,
                    EncryptKey  = passwordSalt
                };
                encryptor.DesEncrypt();

                retval = encryptor.OutString;
            }
            return(retval);
        }
示例#13
0
        public object submit([FromBody] simpleUser siuser)
        {
            DBInit();//数据库初始化

            string token;
            MongoHelper<User> helperUser = new MongoHelper<User>();
            User user = helperUser.FindAll(x => x.usercode == siuser.usercode).First();
            if (user != null)
            {
                //验证密码
                if (user.pwd == DESEncryptor.DesEncrypt(siuser.password))
                {
                    SSO.SsoHelper.SignIn(new SSO.UserInfo { UserCode = siuser.usercode, UserName = user.username, CreateDate = DateTime.Now }, out token);
                    return new { flag = true, username = user.username, token = token };
                }
            }

            return new { flag = false, username = "", token = "" };
        }
示例#14
0
        public static string EncryptStringBySecretKey(string inputString)
        {
            if (string.IsNullOrEmpty(inputString))
            {
                return(string.Empty);
            }

            var encryptor = new DESEncryptor
            {
                InputString = inputString,
                EncryptKey  = FileConfigManager.Instance.SecretKey
            };

            encryptor.DesEncrypt();

            var retval = encryptor.OutString;

            retval = retval.Replace("+", "0add0").Replace("=", "0equals0").Replace("&", "0and0").Replace("?", "0question0").Replace("'", "0quote0").Replace("/", "0slash0");

            return(retval);
        }
示例#15
0
        private void button1_Click(object sender, EventArgs e)
        {
            //读硬盘的序列号
            string strInfo   = "";
            string strMyName = "";
            //HardDiskInfo hdd = AtapiDevice.GetHddInfo(0); // 第一个硬盘
            //str_SerialNumber = hdd.SerialNumber.ToString();
            ManagementClass            cimobject = new ManagementClass("Win32_Processor");
            ManagementObjectCollection moc       = cimobject.GetInstances();

            strMyName = Dns.GetHostName();
            foreach (ManagementObject mo in moc)
            {
                strInfo = mo.Properties["ProcessorId"].Value.ToString();
            }
            strMyName += strInfo;

            DESEncryptor dese1 = new DESEncryptor();

            dese1.InputString = strMyName;
            dese1.EncryptKey  = "lhgynkm0";
            dese1.DesEncrypt();
            string miWen = dese1.OutString;

            dese1 = null;

            err = null;
            string strresult = cs.Register(miWen, SysInitial.LocalDeptName, SysInitial.CurOps.strOperName, out err);

            if (strresult == "connection")
            {
                MessageBox.Show("中心数据库连接失败,请检查网再重试!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                MessageBox.Show("注册申请已经发送至中心,请等待注册完成后,再重新启动系统!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                return;
            }
        }
        /// <summary>
        /// 监控平台初始化
        /// </summary>
        public static void Init()
        {
            //

            //1.初始化超级用户
            User user;
            MongoHelper <User> helperUser = new MongoHelper <User>(WcfGlobal.MongoConnStr, MonitorPlatformManage.dbName);

            user = helperUser.Find(Query.EQ("usercode", new MongoDB.Bson.BsonString("admin")));
            if (user != null)
            {
                //如果存在先删除
                helperUser.Delete(user);
            }
            user          = new User();
            user.usercode = "admin";
            user.pwd      = DESEncryptor.DesEncrypt("123456");
            user.email    = "*****@*****.**";
            user.username = "******";
            helperUser.Insert(user);
            //2.初始化中间件根节点
            MongoHelper <MidNode> helperNode = new MongoHelper <MidNode>(WcfGlobal.MongoConnStr, MonitorPlatformManage.dbName);
            MidNode node;

            node = helperNode.Find(Query.EQ("identify", new MongoDB.Bson.BsonString(WcfGlobal.Identify)));
            if (node != null)
            {
                //如果存在先删除
                helperNode.Delete(node);
            }
            node             = new MidNode();
            node.nodename    = "根节点";
            node.machinecode = "";
            node.regcode     = CoreFrame.Init.HostSettingConfig.GetValue("cdkey");
            node.identify    = WcfGlobal.Identify;
            node.createdate  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            node.delflag     = 0;
            helperNode.Insert(node);
        }
示例#17
0
        private void button4_Click(object sender, System.EventArgs e)
        {
            string                     cpuInfo   = "";
            string                     strMyName = "";
            ManagementClass            cimobject = new ManagementClass("Win32_Processor");
            ManagementObjectCollection moc       = cimobject.GetInstances();

            strMyName = Dns.GetHostName();
            foreach (ManagementObject mo in moc)
            {
                cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
            }
            string str0 = cpuInfo;

            strMyName += cpuInfo.Substring(0, 5);
            DESEncryptor dese = new DESEncryptor();

            //dese.InputString=str0;
            dese.InputString = strMyName;
            dese.EncryptKey  = "lhgynkm0";
            dese.DesEncrypt();
            string miWen = dese.OutString;

            WL(miWen);
            dese          = null;
            textBox6.Text = miWen;
            DESEncryptor dese1 = new DESEncryptor();

            dese1.InputString = miWen;
            dese1.DecryptKey  = "lhgynkm0";
            dese1.DesDecrypt();
            string mingWen = dese1.OutString;

            WL(mingWen);
            dese1         = null;
            textBox7.Text = mingWen;
        }
示例#18
0
        public static string ProcessRequest(string clientId, string plugin, string controller, string method, string jsondata, HeaderParameter para)
        {
            string retJson = null;

            try
            {
                if (plugin == null || controller == null)
                {
                    throw new Exception("插件名称或控制器名称不能为空!");
                }

                if (ClientManage.ClientDic.ContainsKey(clientId) == false)
                {
                    throw new Exception("客户端不存在,正在创建新的连接!");
                }

                if (ClientManage.IsToken == true)//非调试模式下才验证
                {
                    //验证身份,创建连接的时候验证,请求不验证
                    IsAuth(plugin, controller, method, para.token);
                }

                //显示调试信息
                if (WcfGlobal.IsDebug == true)
                {
                    ShowHostMsg(Color.Black, DateTime.Now, "客户端[" + clientId + "]正在执行:" + controller + "." + method + "(" + jsondata + ")");
                }


                begintime();

                #region 执行插件控制器的核心算法
                object[]            paramValue  = null;//jsondata?
                ServiceResponseData retObj      = null;
                LocalPlugin         localPlugin = RemotePluginManage.GetLocalPlugin();
                if (string.IsNullOrEmpty(para.replyidentify) || localPlugin.ServerIdentify == para.replyidentify)
                {
                    if (localPlugin.PluginDic.ContainsKey(plugin) == true)
                    {
                        //先解密再解压
                        string _jsondata = jsondata;
                        //解密参数
                        if (para.isencryptionjson)
                        {
                            DESEncryptor des = new DESEncryptor();
                            des.InputString = _jsondata;
                            des.DesDecrypt();
                            _jsondata = des.OutString;
                        }
                        //解压参数
                        if (para.iscompressjson)
                        {
                            _jsondata = ZipComporessor.Decompress(_jsondata);
                        }

                        ClientRequestData requestData = new ClientRequestData(para.iscompressjson, para.isencryptionjson, para.serializetype);
                        requestData.SetJsonData(_jsondata);
                        requestData.LoginRight = para.LoginRight;

                        EFWCoreLib.CoreFrame.Plugin.ModulePlugin moduleplugin = localPlugin.PluginDic[plugin];
                        retObj = (ServiceResponseData)moduleplugin.WcfServerExecuteMethod(controller, method, paramValue, requestData);

                        if (retObj != null)
                        {
                            retJson = retObj.GetJsonData();
                        }
                        else
                        {
                            retObj = new ServiceResponseData();
                            retObj.Iscompressjson   = para.iscompressjson;
                            retObj.Isencryptionjson = para.isencryptionjson;
                            retObj.Serializetype    = para.serializetype;

                            retJson = retObj.GetJsonData();
                        }

                        retJson = "{\"flag\":0,\"msg\":" + "\"\"" + ",\"data\":" + retJson + "}";
                        //先压缩再加密
                        //压缩结果
                        if (para.iscompressjson)
                        {
                            retJson = ZipComporessor.Compress(retJson);
                        }
                        //加密结果
                        if (para.isencryptionjson)
                        {
                            DESEncryptor des = new DESEncryptor();
                            des.InputString = retJson;
                            des.DesEncrypt();
                            retJson = des.OutString;
                        }
                    }
                    else
                    {
                        throw new Exception("本地插件找不到指定的插件");
                    }
                }
                else//本地插件找不到,就执行远程插件
                {
                    if (RemotePluginManage.GetRemotePlugin().FindIndex(x => x.ServerIdentify == para.replyidentify) > -1)
                    {
                        RemotePlugin rp = RemotePluginManage.GetRemotePlugin().Find(x => x.ServerIdentify == para.replyidentify);
                        string[]     ps = rp.plugin;

                        if (ps.ToList().FindIndex(x => x == plugin) > -1)
                        {
                            retJson = rp.callback.ReplyProcessRequest(para, plugin, controller, method, jsondata);
                        }
                        else
                        {
                            throw new Exception("远程插件找不到指定的插件");
                        }
                    }
                    else
                    {
                        throw new Exception("远程插件找不到指定的回调中间件");
                    }
                }
                #endregion

                double outtime = endtime();
                //记录超时的方法
                if (ClientManage.IsOverTime == true)
                {
                    if (outtime > Convert.ToDouble(ClientManage.OverTime * 1000))
                    {
                        WriterOverTimeLog(outtime, controller + "." + method + "(" + jsondata + ")");
                    }
                }
                //显示调试信息
                if (WcfGlobal.IsDebug == true)
                {
                    ShowHostMsg(Color.Green, DateTime.Now, "客户端[" + clientId + "]收到结果(耗时[" + outtime + "]):" + retJson);
                }

                //更新客户端信息
                ClientManage.UpdateRequestClient(clientId, jsondata == null ? 0 : jsondata.Length, retJson == null ? 0 : retJson.Length);


                if (retJson == null)
                {
                    throw new Exception("插件执行未返回有效数据");
                }

                return(retJson);
            }
            catch (Exception err)
            {
                //记录错误日志
                if (err.InnerException == null)
                {
                    retJson = "{\"flag\":1,\"msg\":" + "\"" + err.Message + "\"" + "}";
                    if (para.iscompressjson)
                    {
                        retJson = ZipComporessor.Compress(retJson);
                    }
                    ShowHostMsg(Color.Red, DateTime.Now, "客户端[" + clientId + "]执行失败:" + err.Message);
                    return(retJson);
                }
                else
                {
                    retJson = "{\"flag\":1,\"msg\":" + "\"" + err.InnerException.Message + "\"" + "}";
                    if (para.iscompressjson)
                    {
                        retJson = ZipComporessor.Compress(retJson);
                    }
                    ShowHostMsg(Color.Red, DateTime.Now, "客户端[" + clientId + "]执行失败:" + err.InnerException.Message);
                    return(retJson);
                }
            }
        }
        private void btnReg_Click(object sender, System.EventArgs e)
        {
            string str_ss1, str_ss2, str_ss3, str_ss4, str_ss5;
            string str_sn1, str_sn2, str_sn3, str_sn4, str_sn5;

            if (txts5.Text.Trim().Length != 5)
            {
                MessageBox.Show("注册序列号不正确,请检查!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                str_sn5 = txts5.Text.Trim();
                str_ss1 = txts5.Text.Trim().Substring(4, 1);
            }
            if (txts4.Text.Trim().Length != 5)
            {
                MessageBox.Show("注册序列号不正确,请检查!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                str_sn4 = txts4.Text.Trim();
                str_ss2 = txts4.Text.Trim().Substring(3, 1);
            }
            if (txts3.Text.Trim().Length != 5)
            {
                MessageBox.Show("注册序列号不正确,请检查!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                str_sn3 = txts3.Text.Trim();
                str_ss3 = txts3.Text.Trim().Substring(2, 1);
            }
            if (txts2.Text.Trim().Length != 5)
            {
                MessageBox.Show("注册序列号不正确,请检查!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                str_sn2 = txts2.Text.Trim();
                str_ss4 = txts2.Text.Trim().Substring(1, 1);
            }
            if (txts1.Text.Trim().Length != 5)
            {
                MessageBox.Show("注册序列号不正确,请检查!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                str_sn1 = txts1.Text.Trim();
                str_ss5 = txts1.Text.Trim().Substring(0, 1);
            }

            //读硬盘的序列号
            string       str_SerialNumber;
            string       str_nb1, str_nb2, str_nb3, str_nb4, str_nb5;
            HardDiskInfo hdd = AtapiDevice.GetHddInfo(0);            // 第一个硬盘

            str_SerialNumber = hdd.SerialNumber.ToString();          //AtapiDevice.getHDDID().Trim();//
            str_nb1          = str_SerialNumber.Substring(0, 1);
            str_nb2          = str_SerialNumber.Substring(1, 1);
            str_nb3          = str_SerialNumber.Substring(2, 1);
            str_nb4          = str_SerialNumber.Substring(3, 1);
            str_nb5          = str_SerialNumber.Substring(4, 1);

            if (str_nb1 == str_ss1 && str_nb2 == str_ss2 && str_nb3 == str_ss3 && str_nb4 == str_ss4 && str_nb5 == str_ss5)
            {
                //加密
                DESEncryptor dese1 = new DESEncryptor();
                dese1.InputString = str_sn1 + "-" + str_sn2 + "-" + str_sn3 + "-" + str_sn4 + "-" + str_sn5;
                dese1.EncryptKey  = "zhenghua0lhgynkm0";
                dese1.DesEncrypt();
                string mingWen = dese1.OutString;
                dese1 = null;

                //写注册表
                string   name    = "ProductKey";
                string   tovalue = mingWen;
                string[] subkeyNames;
                bool     _exist = false;
                if (tovalue != "")
                {
                    RegistryKey hklm     = Registry.LocalMachine;
                    RegistryKey software = hklm.OpenSubKey("SOFTWARE", true);
                    subkeyNames = software.GetSubKeyNames();
                    foreach (string keyName in subkeyNames)
                    {
                        if (keyName == "KMMWAMS")
                        {
                            RegistryKey aimdir = software.OpenSubKey("KMMWAMS", true);
                            aimdir.SetValue(name, tovalue);
                            _exist = true;
                        }
                    }
                    if (!_exist)
                    {
                        RegistryKey aimdir = software.CreateSubKey("KMMWAMS");
                        aimdir.SetValue(name, tovalue);
                    }

                    MessageBox.Show("恭喜,您已成功注册,系统将自动退出,稍后请重新启动会员管理系统!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                    Application.Exit();
                }
                else
                {
                    MessageBox.Show("注册失败,请稍后重试!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("注册序列号不正确,请检查!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
        }
示例#20
0
        /// <summary>
        /// 向服务发送异步请求
        /// 客户端建议不要用多线程,都采用异步请求方式
        /// </summary>
        /// <param name="controller">插件名@控制器名称</param>
        /// <param name="method">方法名称</param>
        /// <param name="jsondata">数据</param>
        /// <returns>返回Json数据</returns>
        public IAsyncResult RequestAsync(string controller, string method, Action <ClientRequestData> requestAction, Action <ServiceResponseData> action)
        {
            if (clientObj == null)
            {
                throw new Exception("还没有创建连接!");
            }
            try
            {
                ClientRequestData requestData = new ClientRequestData(IsCompressJson, IsEncryptionJson, serializeType);
                if (requestAction != null)
                {
                    requestAction(requestData);
                }

                string jsondata = requestData.GetJsonData();      //获取序列化的请求数据

                if (requestData.Iscompressjson)                   //开启压缩
                {
                    jsondata = ZipComporessor.Compress(jsondata); //压缩传入参数
                }
                if (requestData.Isencryptionjson)                 //开启加密
                {
                    DESEncryptor des = new DESEncryptor();
                    des.InputString = jsondata;
                    des.DesEncrypt();
                    jsondata = des.OutString;
                }

                DuplexBaseServiceClient _wcfService = clientObj.WcfService;
                IAsyncResult            result      = null;

                AddMessageHeader(_wcfService.InnerDuplexChannel as IContextChannel, "", requestData.Iscompressjson, requestData.Isencryptionjson, requestData.Serializetype, requestData.LoginRight, (() =>
                {
                    AsyncCallback callback = delegate(IAsyncResult r)
                    {
                        string retJson = _wcfService.EndProcessRequest(r);

                        if (requestData.Isencryptionjson)//解密结果
                        {
                            DESEncryptor des = new DESEncryptor();
                            des.InputString = retJson;
                            des.DesDecrypt();
                            retJson = des.OutString;
                        }
                        if (requestData.Iscompressjson)//解压结果
                        {
                            retJson = ZipComporessor.Decompress(retJson);
                        }

                        string retData = "";
                        object Result = JsonConvert.DeserializeObject(retJson);
                        int ret = Convert.ToInt32((((Newtonsoft.Json.Linq.JObject)Result)["flag"]).ToString());
                        string msg = (((Newtonsoft.Json.Linq.JObject)Result)["msg"]).ToString();
                        if (ret == 1)
                        {
                            throw new Exception(msg);
                        }
                        else
                        {
                            retData = ((Newtonsoft.Json.Linq.JObject)(Result))["data"].ToString();
                        }

                        ServiceResponseData responsedata = new ServiceResponseData();
                        responsedata.Iscompressjson = requestData.Iscompressjson;
                        responsedata.Isencryptionjson = requestData.Isencryptionjson;
                        responsedata.Serializetype = requestData.Serializetype;
                        responsedata.SetJsonData(retData);

                        action(responsedata);
                    };
                    result = _wcfService.BeginProcessRequest(clientObj.ClientID, clientObj.PluginName, controller, method, jsondata, callback, null);
                }));

                new Action(delegate()
                {
                    if (IsHeartbeat == false)//如果没有启动心跳,则请求发送心跳
                    {
                        ServerConfigRequestState = false;
                        Heartbeat();
                    }
                }).BeginInvoke(null, null);//异步执行

                return(result);
            }
            catch (Exception e)
            {
                ServerConfigRequestState = false;
                ReConnection(true);//连接服务主机失败,重连
                throw new Exception(e.Message + "\n连接服务主机失败,请联系管理员!");
            }
        }
示例#21
0
		private void button4_Click(object sender, System.EventArgs e)
		{
			string str_SerialNumber;
			string str_nb1,str_nb2,str_nb3,str_nb4,str_nb5;
            string miWen1=textBox8.Text;
			if (textBox8.Text.Trim()=="")
			{
				MessageBox.Show("机器码不能为空");
				return;
			}
			DESEncryptor dese2=new DESEncryptor();
			dese2.InputString=miWen1;
			dese2.DecryptKey="lhgynkm0";
			dese2.DesDecrypt();
			string mingWen1=dese2.OutString;
			WL(mingWen1);
			dese2=null;

          	str_SerialNumber=mingWen1;
			str_nb1=str_SerialNumber.Substring(2,1);
			str_nb2=str_SerialNumber.Substring(3,1);
			str_nb3=str_SerialNumber.Substring(4,1);
			str_nb4=str_SerialNumber.Substring(5,1);
			str_nb5=str_SerialNumber.Substring(6,1);
			label1.Text=mingWen1;

			int num;
			System.Random random;
			System.Collections.ArrayList array;

			random= new Random();
			array=new System.Collections.ArrayList();
 
			//保存第一个数到 array 对象
			array.Add((int)random.Next(1000,9999));
 
			int i,j,m=1; 
			int n=0;
			string str0=null,str1;
			//循环取6不重复的数字
			while(m<6)
			{
				n=n+1;
				num=random.Next(1000,9999);
 
				//判断是否已经存在
				for(j=0;j<array.Count;j++)
				{
					//如果数列中的数字比随机数大,则该随机数为新数,插入到大数的前面
					if (num<(int)array[j])
					{
						array.Insert(j,num);
						m++;
					}
					//相等,则说明存在,跳出循环重新取数
					if(num==(int)array[j])
						break;
     
				}
				string str_num=num.ToString();
				if (n==1)
				{
					textBox1.Text=str_nb5 + num.ToString();
					str1=str_nb5 + num.ToString();
					str0=str0+str1;
				}
				if (n==2)
				{
					string str_num20,str_num21;
					str_num20=str_num.Substring(0,1);
					str_num21=str_num.Substring(1,3);
					textBox2.Text=str_num20 + str_nb4 + str_num21;
					str1=str_num20 + str_nb4 + str_num21;
					str0=str0+"-"+str1;
				}
				if (n==3)
				{
					string str_num30,str_num31;
					str_num30=str_num.Substring(0,2);
					str_num31=str_num.Substring(2,2);
					textBox3.Text=str_num30 + str_nb3 + str_num31;
					str1=str_num30 + str_nb3 + str_num31;
					str0=str0+"-"+str1;
				}
				if (n==4)
				{
					string str_num40,str_num41;
					str_num40=str_num.Substring(0,3);
					str_num41=str_num.Substring(3,1);
					textBox4.Text=str_num40 + str_nb2 + str_num41;
					str1=str_num40 + str_nb2 + str_num41;
					str0=str0+"-"+str1;
				}
				if (n==5)
				{
					textBox5.Text=num.ToString() + str_nb1;
					str1=num.ToString() + str_nb1;
					str0=str0+"-"+str1;
				}
				//加密
				DESEncryptor dese=new DESEncryptor();
                dese.InputString ="ynkm"+ mingWen1 + "dxkj";
				dese.EncryptKey="lhgynkm0";
				dese.DesEncrypt();
				string miWen=dese.OutString;
				WL(miWen);
				dese=null;
				textBox6.Text=miWen;
                //解密
				DESEncryptor dese1=new DESEncryptor();
				dese1.InputString=miWen;
				dese1.DecryptKey="lhgynkm0";
				dese1.DesDecrypt();
				string mingWen=dese1.OutString;
				WL(mingWen);
				dese1=null;
				textBox7.Text=mingWen;
				//所有的数都比随机数小……
				if(j==array.Count )
				{
					array.Add(num);
					m++; 
				}
			}
   
			for(i=0;i<6;i++)
			{
				Console.Write(array[i].ToString() + " ");
			}
			Console.Read();
 
		}
示例#22
0
        //执行服务核心方法
        private static string ExecuteService(string plugin, string controller, string method, string jsondata, HeaderParameter para)
        {
            string retJson = null;

            try
            {
                #region 执行插件控制器的核心算法
                object[]            paramValue = null;//jsondata?
                ServiceResponseData retObj     = null;

                //先解密再解压
                string _jsondata = jsondata;
                //解密参数
                if (para.isencryptionjson)
                {
                    DESEncryptor des = new DESEncryptor();
                    des.InputString = _jsondata;
                    des.DesDecrypt();
                    _jsondata = des.OutString;
                }
                //解压参数
                if (para.iscompressjson)
                {
                    _jsondata = ZipComporessor.Decompress(_jsondata);
                }

                ClientRequestData requestData = new ClientRequestData(para.iscompressjson, para.isencryptionjson, para.serializetype);
                requestData.SetJsonData(_jsondata);
                requestData.LoginRight = para.LoginRight;
                //获取插件服务
                EFWCoreLib.CoreFrame.Plugin.ModulePlugin moduleplugin = CoreFrame.Init.AppPluginManage.PluginDic[plugin];
                retObj = (ServiceResponseData)moduleplugin.WcfServerExecuteMethod(controller, method, paramValue, requestData);

                if (retObj != null)
                {
                    retJson = retObj.GetJsonData();
                }
                else
                {
                    retObj = new ServiceResponseData();
                    retObj.Iscompressjson   = para.iscompressjson;
                    retObj.Isencryptionjson = para.isencryptionjson;
                    retObj.Serializetype    = para.serializetype;

                    retJson = retObj.GetJsonData();
                }

                retJson = "{\"flag\":0,\"msg\":" + "\"\"" + ",\"data\":" + retJson + "}";
                //先压缩再加密
                //压缩结果
                if (para.iscompressjson)
                {
                    retJson = ZipComporessor.Compress(retJson);
                }
                //加密结果
                if (para.isencryptionjson)
                {
                    DESEncryptor des = new DESEncryptor();
                    des.InputString = retJson;
                    des.DesEncrypt();
                    retJson = des.OutString;
                }


                #endregion

                return(retJson);
            }
            catch (Exception err)
            {
                throw err;
            }
        }
示例#23
0
        private void btnReg_Click(object sender, System.EventArgs e)
        {
            string str_ss1, str_ss2, str_ss3, str_ss4, str_ss5;
            string str_sn1, str_sn2, str_sn3, str_sn4, str_sn5;

            if (txts5.Text.Trim().Length != 5)
            {
                MessageBox.Show("注册序列号不正确,请检查!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                str_sn5 = txts5.Text.Trim();
                str_ss1 = txts5.Text.Trim().Substring(4, 1);
            }
            if (txts4.Text.Trim().Length != 5)
            {
                MessageBox.Show("注册序列号不正确,请检查!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                str_sn4 = txts4.Text.Trim();
                str_ss2 = txts4.Text.Trim().Substring(3, 1);
            }
            if (txts3.Text.Trim().Length != 5)
            {
                MessageBox.Show("注册序列号不正确,请检查!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                str_sn3 = txts3.Text.Trim();
                str_ss3 = txts3.Text.Trim().Substring(2, 1);
            }
            if (txts2.Text.Trim().Length != 5)
            {
                MessageBox.Show("注册序列号不正确,请检查!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                str_sn2 = txts2.Text.Trim();
                str_ss4 = txts2.Text.Trim().Substring(1, 1);
            }
            if (txts1.Text.Trim().Length != 5)
            {
                MessageBox.Show("注册序列号不正确,请检查!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                str_sn1 = txts1.Text.Trim();
                str_ss5 = txts1.Text.Trim().Substring(0, 1);
            }

            //读硬盘的序列号
            string strInfo = "";
            string str_nb1, str_nb2, str_nb3, str_nb4, str_nb5;

            if (SysInitial.CurOps.strOperName == "罗怀刚000000")
            {
                strInfo = "5VD3SLHG";
            }
            else
            {
                //HardDiskInfo hdd = AtapiDevice.GetHddInfo(0); // 第一个硬盘
                //str_SerialNumber = hdd.SerialNumber.ToString();
                ManagementClass            cimobject = new ManagementClass("Win32_Processor");
                ManagementObjectCollection moc       = cimobject.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    strInfo = mo.Properties["ProcessorId"].Value.ToString();
                }
            }

            str_nb1 = strInfo.Substring(2, 1);
            str_nb2 = strInfo.Substring(3, 1);
            str_nb3 = strInfo.Substring(4, 1);
            str_nb4 = strInfo.Substring(5, 1);
            str_nb5 = strInfo.Substring(6, 1);

            if (str_nb1 == str_ss1 && str_nb2 == str_ss2 && str_nb3 == str_ss3 && str_nb4 == str_ss4 && str_nb5 == str_ss5)
            {
                //加密
                DESEncryptor dese1 = new DESEncryptor();
                dese1.InputString = str_sn1 + "-" + str_sn2 + "-" + str_sn3 + "-" + str_sn4 + "-" + str_sn5;
                dese1.EncryptKey  = "lhgynkm0";
                dese1.DesEncrypt();
                string mingWen = dese1.OutString;
                dese1 = null;

                //写注册表
                string   name     = "ProductKey";
                string   tovalue  = mingWen;
                string   name1    = "AMSPath";
                string   tovalue1 = Application.StartupPath;
                string[] subkeyNames;
                bool     _exist = false;
                if (tovalue != "")
                {
                    RegistryKey hklm     = Registry.LocalMachine;
                    RegistryKey software = hklm.OpenSubKey("SOFTWARE", true);
                    subkeyNames = software.GetSubKeyNames();
                    foreach (string keyName in subkeyNames)
                    {
                        if (keyName == "KMMWAMS")
                        {
                            RegistryKey aimdir = software.OpenSubKey("KMMWAMS", true);
                            aimdir.SetValue(name, tovalue);
                            aimdir.SetValue(name1, tovalue1);
                            _exist = true;
                        }
                    }
                    if (!_exist)
                    {
                        RegistryKey aimdir = software.CreateSubKey("KMMWAMS");
                        aimdir.SetValue(name, tovalue);
                        aimdir.SetValue(name1, tovalue1);
                    }

                    MessageBox.Show("恭喜,您已成功注册,系统将自动退出,稍后请重新启动会员管理系统!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                    Application.Exit();
                }
                else
                {
                    MessageBox.Show("注册失败,请稍后重试!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("注册序列号不正确,请检查!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
        }
示例#24
0
        /// <summary>
        /// 向服务发送请求
        /// </summary>
        /// <param name="controller">控制器名称</param>
        /// <param name="method">方法名称</param>
        /// <param name="requestAction">数据</param>
        /// <returns>返回Json数据</returns>
        public ServiceResponseData Request(string controller, string method, Action <ClientRequestData> requestAction)
        {
            if (clientObj == null)
            {
                throw new Exception("还没有创建连接!");
            }
            while (baseServiceClient.State == CommunicationState.Opening || clientObj.ClientID == null)//解决并发问题
            {
                Thread.Sleep(400);
            }

            if (baseServiceClient.State == CommunicationState.Closed || baseServiceClient.State == CommunicationState.Faulted)
            {
                ReConnection(true);//连接服务主机失败,重连
            }
            try
            {
                ClientRequestData requestData = new ClientRequestData(serverConfig.IsCompressJson, serverConfig.IsEncryptionJson, (SerializeType)serverConfig.SerializeType);
                if (requestAction != null)
                {
                    requestAction(requestData);
                }

                string jsondata = requestData.GetJsonData();      //获取序列化的请求数据

                if (requestData.Iscompressjson)                   //开启压缩
                {
                    jsondata = ZipComporessor.Compress(jsondata); //压缩传入参数
                }
                if (requestData.Isencryptionjson)                 //开启加密
                {
                    DESEncryptor des = new DESEncryptor();
                    des.InputString = jsondata;
                    des.DesEncrypt();
                    jsondata = des.OutString;
                }
                string retJson = "";
#if ClientProxy
                BaseServiceClient _wcfService = clientObj.WcfService;
                AddMessageHeader(_wcfService.InnerChannel as IContextChannel, "", requestData.Iscompressjson, requestData.Isencryptionjson, requestData.Serializetype, requestData.LoginRight, (() =>
                {
                    retJson = _wcfService.ProcessRequest(clientObj.ClientID, clientObj.PluginName, controller, method, jsondata);
                }));
#else
                DuplexBaseServiceClient _wcfService = clientObj.WcfService;
                AddMessageHeader(_wcfService.InnerDuplexChannel as IContextChannel, "", requestData.Iscompressjson, requestData.Isencryptionjson, requestData.Serializetype, requestData.LoginRight, (() =>
                {
                    retJson = _wcfService.ProcessRequest(clientObj.ClientID, clientObj.PluginName, controller, method, jsondata);
                }));
#endif
                if (requestData.Isencryptionjson)//解密结果
                {
                    DESEncryptor des = new DESEncryptor();
                    des.InputString = retJson;
                    des.DesDecrypt();
                    retJson = des.OutString;
                }
                if (requestData.Iscompressjson)//解压结果
                {
                    retJson = ZipComporessor.Decompress(retJson);
                }

                new Action(delegate()
                {
                    if (serverConfig.IsHeartbeat == false)//如果没有启动心跳,则请求发送心跳
                    {
                        ServerConfigRequestState = false;
                        Heartbeat();
                    }
                }).BeginInvoke(null, null);//异步执行

                string retData = "";
                object Result  = JsonConvert.DeserializeObject(retJson);
                int    ret     = Convert.ToInt32((((Newtonsoft.Json.Linq.JObject)Result)["flag"]).ToString());
                string msg     = (((Newtonsoft.Json.Linq.JObject)Result)["msg"]).ToString();
                if (ret == 1)
                {
                    throw new Exception(msg);
                }
                else
                {
                    retData = ((Newtonsoft.Json.Linq.JObject)(Result))["data"].ToString();
                }

                ServiceResponseData responsedata = new ServiceResponseData();
                responsedata.Iscompressjson   = requestData.Iscompressjson;
                responsedata.Isencryptionjson = requestData.Isencryptionjson;
                responsedata.Serializetype    = requestData.Serializetype;
                responsedata.SetJsonData(retData);

                return(responsedata);
            }
            catch (Exception e)
            {
                ServerConfigRequestState = false;
                //ReConnection(true);//连接服务主机失败,重连
                //throw new Exception(e.Message + "\n连接服务主机失败,请联系管理员!");
                throw new Exception(e.Message);
            }
        }
示例#25
0
        public static string ReplyProcessRequest(string plugin, string controller, string method, string jsondata, HeaderParameter para)
        {
            string retJson = null;

            try
            {
                //显示调试信息
                if (WcfGlobal.IsDebug == true)
                {
                    ShowHostMsg(Color.Black, DateTime.Now, "客户端[本地回调]正在执行:" + controller + "." + method + "(" + jsondata + ")");
                }

                begintime();

                #region 执行插件控制器的核心算法
                object[]            paramValue  = null;//jsondata?
                ServiceResponseData retObj      = null;
                LocalPlugin         localPlugin = RemotePluginManage.GetLocalPlugin();
                if (string.IsNullOrEmpty(para.replyidentify) || localPlugin.ServerIdentify == para.replyidentify)
                {
                    if (localPlugin.PluginDic.ContainsKey(plugin) == true)
                    {
                        //先解密再解压
                        string _jsondata = jsondata;
                        //解密参数
                        if (para.isencryptionjson)
                        {
                            DESEncryptor des = new DESEncryptor();
                            des.InputString = _jsondata;
                            des.DesDecrypt();
                            _jsondata = des.OutString;
                        }
                        //解压参数
                        if (para.iscompressjson)
                        {
                            _jsondata = ZipComporessor.Decompress(_jsondata);
                        }

                        ClientRequestData requestData = new ClientRequestData(para.iscompressjson, para.isencryptionjson, para.serializetype);
                        requestData.SetJsonData(_jsondata);
                        requestData.LoginRight = para.LoginRight;

                        EFWCoreLib.CoreFrame.Plugin.ModulePlugin moduleplugin = localPlugin.PluginDic[plugin];
                        retObj = (ServiceResponseData)moduleplugin.WcfServerExecuteMethod(controller, method, paramValue, requestData);

                        if (retObj != null)
                        {
                            retJson = retObj.GetJsonData();
                        }
                        else
                        {
                            retObj = new ServiceResponseData();
                            retObj.Iscompressjson   = para.iscompressjson;
                            retObj.Isencryptionjson = para.isencryptionjson;
                            retObj.Serializetype    = para.serializetype;

                            retJson = retObj.GetJsonData();
                        }

                        retJson = "{\"flag\":0,\"msg\":" + "\"\"" + ",\"data\":" + retJson + "}";
                        //先压缩再加密
                        //压缩结果
                        if (para.iscompressjson)
                        {
                            retJson = ZipComporessor.Compress(retJson);
                        }
                        //加密结果
                        if (para.isencryptionjson)
                        {
                            DESEncryptor des = new DESEncryptor();
                            des.InputString = retJson;
                            des.DesEncrypt();
                            retJson = des.OutString;
                        }
                    }
                    else
                    {
                        throw new Exception("本地插件找不到指定的插件");
                    }
                }
                else//本地插件找不到,就执行远程插件
                {
                    if (RemotePluginManage.GetRemotePlugin().FindIndex(x => x.ServerIdentify == para.replyidentify) > -1)
                    {
                        RemotePlugin rp = RemotePluginManage.GetRemotePlugin().Find(x => x.ServerIdentify == para.replyidentify);
                        string[]     ps = rp.plugin;

                        if (ps.ToList().FindIndex(x => x == plugin) > -1)
                        {
                            retJson = rp.callback.ReplyProcessRequest(para, plugin, controller, method, jsondata);
                        }
                        else
                        {
                            throw new Exception("远程插件找不到指定的插件");
                        }
                    }
                    else
                    {
                        throw new Exception("远程插件找不到指定的回调中间件");
                    }
                }
                #endregion

                //System.Threading.Thread.Sleep(20000);//测试并发问题,此处也没有问题
                double outtime = endtime();
                //记录超时的方法
                if (ClientManage.IsOverTime == true)
                {
                    if (outtime > Convert.ToDouble(ClientManage.OverTime * 1000))
                    {
                        WriterOverTimeLog(outtime, controller + "." + method + "(" + jsondata + ")");
                    }
                }
                //显示调试信息
                if (WcfGlobal.IsDebug == true)
                {
                    ShowHostMsg(Color.Green, DateTime.Now, "客户端[本地回调]收到结果(耗时[" + outtime + "]):" + retJson);
                }

                if (retJson == null)
                {
                    throw new Exception("请求的插件未获取到有效数据");
                }

                return(retJson);
            }
            catch (Exception err)
            {
                //记录错误日志
                //EFWCoreLib.CoreFrame.EntLib.ZhyContainer.CreateException().HandleException(err, "HISPolicy");

                if (err.InnerException == null)
                {
                    retJson = "{\"flag\":1,\"msg\":" + "\"" + err.Message + "\"" + "}";
                    if (para.iscompressjson)
                    {
                        retJson = ZipComporessor.Compress(retJson);
                    }
                    ShowHostMsg(Color.Red, DateTime.Now, "客户端[本地回调]执行失败:" + err.Message);
                    return(retJson);
                }
                else
                {
                    retJson = "{\"flag\":1,\"msg\":" + "\"" + err.InnerException.Message + "\"" + "}";
                    if (para.iscompressjson)
                    {
                        retJson = ZipComporessor.Compress(retJson);
                    }
                    ShowHostMsg(Color.Red, DateTime.Now, "客户端[本地回调]执行失败:" + err.InnerException.Message);
                    return(retJson);
                }
            }
        }