예제 #1
0
파일: QDAddIn.cs 프로젝트: mwilian/demos
        private bool ValidateLicense(string _pathLicense)
        {
            BUS.CommonControl ctr  = new CommonControl();
            object            data = ctr.executeScalar(@"SELECT SUN_DATA  FROM SSINSTAL WHERE INS_TB='LCS' and INS_KEY='QD'");

            if (data != null)//File.Exists(_pathLicense.Replace("file:\\", ""))
            {
                //StreamReader reader = new StreamReader(_pathLicense);
                //string result = reader.ReadLine();
                string      kq      = RC2.DecryptString(data.ToString(), Form_QD._key, Form_QD._iv, Form_QD._padMode, Form_QD._opMode);
                string[]    tmp     = kq.Split(';');
                DTO.License license = new DTO.License();
                license.CompanyName  = tmp[0];
                license.ExpiryDate   = Convert.ToInt32(tmp[1]);
                license.Modules      = tmp[2];
                license.NumUsers     = Convert.ToInt32(tmp[3]);
                license.SerialNumber = tmp[4];
                license.Key          = tmp[5];
                //license.SerialCPU = tmp[6];
                //BUS.CommonControl ctr = new BUS.CommonControl();
                license.SerialCPU = ctr.executeScalar(@"SELECT   CONVERT(varchar(200), SERVERPROPERTY('servername'))").ToString(); //"BFEBFBFF000006FD";
                //reader.Close();


                string param = license.CompanyName + license.SerialNumber + license.NumUsers.ToString() + license.Modules + license.ExpiryDate.ToString() + license.SerialCPU;


                string temp = RC2.EncryptString(param, Form_QD._key, Form_QD._iv, Form_QD._padMode, Form_QD._opMode);
                string key  = Convert.ToBase64String(new System.Security.Cryptography.SHA1CryptoServiceProvider().ComputeHash(Encoding.ASCII.GetBytes(temp)));
                if (key == license.Key)
                {
                    int now = Convert.ToInt32(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00"));
                    //BUS.CommonControl ctr = new CommonControl();
                    object dt = ctr.executeScalar("select getdate()", _strConnect);
                    if (dt != null && dt is DateTime)
                    {
                        now = Convert.ToInt32(((DateTime)dt).Year.ToString() + ((DateTime)dt).Month.ToString("00") + ((DateTime)dt).Day.ToString("00"));
                    }
                    if (now > license.ExpiryDate)
                    {
                        _sErr = "Your license is expired!";
                    }
                    else
                    {
                        //if (license.Modules.Length == 4 && license.Modules.Substring(3) == "Y")
                        return(true);
                        //else _flagQDADD = false;
                    }
                }
                else
                {
                    _sErr = "Application have not license!";
                }
            }
            else
            {
                _sErr = "Application have not license!";
            }
            return(false);
        }
예제 #2
0
        public void SaveConfig(string filename)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter  sw = new StringWriter(sb);

            WriteXml(sw);
            sw.Close();
            string       temp    = RC2.EncryptString(sb.ToString(), Form_QD._key, Form_QD._iv, Form_QD._padMode, Form_QD._opMode);
            StreamWriter streamw = new StreamWriter(filename);

            streamw.Write(temp);
            streamw.Close();
        }
예제 #3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            DTO.License license = GetDataFromForm();
            string      param   = license.CompanyName + license.SerialNumber + license.NumUsers.ToString() + license.Modules + license.ExpiryDate.ToString() + license.SerialCPU;


            string tmp = RC2.EncryptString(param, _key, _iv, _padMode, _opMode);
            string key = Convert.ToBase64String(new System.Security.Cryptography.SHA1CryptoServiceProvider().ComputeHash(Encoding.ASCII.GetBytes(tmp)));

            if (key == license.Key)
            {
                String kq = license.CompanyName + ";" +
                            license.ExpiryDate + ";" +
                            license.Modules + ";" +
                            license.NumUsers + ";" +
                            license.SerialNumber + ";" +
                            license.Key + ";" +
                            license.SerialCPU;


                BUS.CommonControl ctr    = new BUS.CommonControl();
                string            query  = @"if EXISTS(SELECT INS_KEY  FROM SSINSTAL WHERE INS_TB='LCS' and INS_KEY='QD') 
UPDATE SSINSTAL SET SUN_DATA = '{0}' WHERE INS_TB='LCS' and INS_KEY='QD'
else 
INSERT INTO SSINSTAL(INS_TB ,INS_KEY ,SUN_DATA) VALUES ( 'LCS' ,'QD' ,'{0}')";
                string            result = RC2.EncryptString(kq, _key, _iv, _padMode, _opMode);
                query = string.Format(query, result);
                ctr.executeNonQuery(query);
                //StreamWriter writerStream = new StreamWriter(_pathLicense.Replace("file:\\", ""));
                //writerStream.WriteLine(result);
                //writerStream.Close();

                Close();
                DialogResult = DialogResult.OK;
            }
            else
            {
                lbErr.Text = "Registry fail";
            }
        }