Esempio n. 1
0
        public bool Validate(string publicKey, string val, bool valifyDate, out string msg)
        {
            msg = "注册码不正确";
            bool succ = false;
            bool validateComputerNo = false;
            bool validateDate       = !valifyDate;

            try
            {
                RSAHelper rsaHelper = new RSAHelper();
                string    ming      = rsaHelper.DecryptByPublicKey(val, publicKey);
                string[]  vals      = ming.Split('-');
                if (vals.Length == 3)
                {
                    StationNo  = vals[0];
                    ComputerNo = vals[1];
                    MaxDate    = vals[2];

                    SoftReg softReg  = new SoftReg();
                    string  valifyNo = softReg.GetMNum();
                    validateComputerNo = valifyNo.Equals(ComputerNo);
                    if (!validateComputerNo)
                    {
                        msg = "机器码不匹配";
                    }

                    if (valifyDate)
                    {
                        DateTime d;
                        if (DateTime.TryParse(MaxDate, out d))
                        {
                            validateDate = d < DateTime.Now;
                            EndDate      = d;
                            if (validateDate)
                            {
                                msg = "注册码已过期";
                            }
                        }
                    }
                    if (!valifyDate)
                    {
                        succ = validateComputerNo;
                    }
                    else
                    {
                        succ = validateComputerNo && !validateDate;
                    }
                }
            }
            catch (Exception ex)
            {
                succ = false;
            }
            return(succ);
        }
Esempio n. 2
0
 private void Init()
 {
     try
     {
         SoftReg softReg = new SoftReg();
         txtComputerNo.Text = softReg.GetMNum();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }