예제 #1
0
        /// <summary>
        /// 生成注册码
        /// </summary>
        /// <param name="MachineKey"></param>
        /// <param name="Timeout"></param>
        /// <returns></returns>
        public string GenRegisterKey(string MachineKey, EnumTimeOut Timeout)
        {
            var ClientMachineKey = MachineNumberModel.FromString(MachineKey);
            var registerKeyModel = new RegisterKeyModel()
            {
                RegisterKey     = info.GetRNum(ClientMachineKey.HardwareID, false),
                TimeLimit       = Timeout,                      //1
                Timestamp5      = ClientMachineKey.Timestamp5,  //5
                RegistTimeTicks = ClientMachineKey.Timestamp20, //20
                //BFEBFBFF000906EA52176B8A006368747630831805632834385645
            };

            //MessageBox.Show($"生成的注册码:{ClientMachineKey.HardwareID}\n{registerKeyModel.RegisterKey}");
            return(registerKeyModel.ToString());
        }
예제 #2
0
        /// <summary>
        /// 点击注册的时候操作
        /// </summary>
        /// <param name="RegisterKey"></param>
        /// <returns></returns>
        public bool CheckRegisterKey(string MachineKey, string RegisterKey)
        {
            var MachineModelIn = MachineNumberModel.FromString(MachineKey);
            var ModelIn        = RegisterKeyModel.FromString(RegisterKey);

            //MessageBox.Show($"{ModelIn.Timestamp5}\n{MachineModelIn.Timestamp5}\n");


            if (ModelIn.Timestamp5 != MachineModelIn.Timestamp5)
            {
                throw new Exception("已经过时的注册码");
            }

            string ClacRegisterKey = info.GetRNum(MachineModelIn.HardwareID, true);

            //MessageBox.Show($"获取的注册码:{MachineModelIn.HardwareID}\n{ClacRegisterKey}");
            //说明从注册信息里读的是正确的,但是再次获取机器码就不对了
            //MessageBox.Show($"4\n{ModelIn.RegisterKey}\n{ClacRegisterKey}\n{ModelIn.RegisterKey.Length}\n{ClacRegisterKey.Length}");
            if (ModelIn.RegisterKey.Trim() == ClacRegisterKey.Trim())
            {
                //注册成功的时候写入文件


                using (var s = new FileStream(FilePath, FileMode.Create, FileAccess.Write))
                {
                    var bf = new BinaryFormatter();
                    bf.Serialize(s, ModelIn);
                    RegEditor.WriteRegisterValue(RegisterKey);

                    RegEditor.WriteRemainTime("0");
                    DaysLeft = TimeArr[(int)ModelIn.TimeLimit];
                    return(true);
                }
            }
            return(false);
        }