Beispiel #1
0
        private void frmRegHis_Load(object sender, EventArgs e)
        {
            try
            {
                string strRegAllInfo = File.ReadAllText(strRegKeyFile);


                PzCompression pzCom = PzCompressionHelper.getPzCompression(CompressionType.GZip);
                int           nIdx  = 0;

                byte[] byTmp;
                using (FileStream fsReg = new FileStream(strRegKeyFile, FileMode.Open, FileAccess.Read))
                {
                    while (true)
                    {
                        byTmp = new byte[4];
                        if (fsReg.Read(byTmp, 0, 4) < 1)
                        {
                            break;
                        }

                        int nLen = BitConverter.ToInt32(byTmp, 0);
                        byTmp = new byte[nLen];
                        fsReg.Read(byTmp, 0, nLen);

                        textBox1.Text += Encoding.Unicode.GetString(pzCom.DeCompress(byTmp)) + "\r\n";

                        nIdx++;
                    }
                }
                label1.Text = string.Format("共授权完成{0}台机器", nIdx);
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #2
0
        public static bool DeCompRegNum(string _strRegText, out string _strRegCode, out int _nCurrID, out int _nMaxID)
        {
            bool bRt = true;

            _strRegCode = "";
            try
            {
                PzCompression pzCom = PzCompressionHelper.getPzCompression(CompressionType.GZip);

                string strRegNumDeCompress = pzCom.DeCompress(_strRegText);
                _strRegCode = strRegNumDeCompress.Substring(8);

                //读取授权码中可以授权的数量
                _nCurrID = Convert.ToInt32(strRegNumDeCompress.Substring(0, 4));
                _nMaxID  = Convert.ToInt32(strRegNumDeCompress.Substring(4, 4));

                if (_nCurrID < 0 || _nMaxID < 1 || _nCurrID > _nMaxID)
                {
                    _nCurrID = 0;
                    _nMaxID  = 0;
                    bRt      = false;
                }
                else if (_nCurrID == _nMaxID)
                {
                    bRt = false;
                }
            }
            catch (Exception ex)
            {
                _nCurrID = 0;
                _nMaxID  = 0;
                bRt      = false;
            }

            return(bRt);
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //txbYzm.Text = DBA.Code.encrypt("I173387EFIE8");

            if (String.IsNullOrEmpty(txbJqh.Text))
            {
                MessageBox.Show("请完整填写注册信息!");
                txbJqh.Focus();
                return;
            }
            else
            {
                //原机器码
                string strDePcNm = DBA.Code.DecryptionAll(txbJqh.Text.Trim());

                //机器授权码
                string strPcNm_regNm = RegUtility.GetRegNumber(strDePcNm);

                //生成时间
                string strC_Date    = DateTime.Now.ToString("yyyy-MM-dd"); //yyyy-MM-dd HH:mm:ss
                string strSqjz_Date = dtPkSqEnd.Value.ToString("yyyy-MM-dd");

                //加密机器授权码及数据使用授权码[x|BegData|x|x]
                txbYzm.Text = DBA.Code.encrypt(strPcNm_regNm + strC_Date + strSqjz_Date);

                //复制注册码
                Clipboard.SetText(this.txbYzm.Text.Trim());
            }

            //增加授权记录
            using (StreamWriter sw = new StreamWriter(shFile, true))
            {
                //分别是时间、机器号、授权信息、注册码
                string strRegDtAndUInfo = DateTime.Now.ToString() + " 为 " + txbUserInfo.Text.Trim();
                string strRegJQH        = "机器号:" + txbJqh.Text.Trim();
                string strRegZCM        = "授权码:" + txbYzm.Text;

                string strRegAllInfo = string.Format("{0}\r\n{1}\r\n{2}\r\n{3}", strRegDtAndUInfo, strRegJQH, strRegZCM, "-------------------------------------------------");
                sw.WriteLine(strRegAllInfo);

                //加密
                //using (StreamWriter swReg = new StreamWriter(strRegKeyFile, true))
                //{
                //    PzCompression pzCom = PzCompressionHelper.getPzCompression(CompressionType.GZip);
                //    byte[] byTmp = pzCom.CompressToByte(strRegAllInfo);
                //    swReg.WriteLine(swReg);
                //}

                using (FileStream fsReg = new FileStream(strRegKeyFile, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    fsReg.Position = fsReg.Length;

                    PzCompression pzCom = PzCompressionHelper.getPzCompression(CompressionType.GZip);
                    byte[]        byTmp = pzCom.CompressToByte(strRegAllInfo);

                    byte[] byLen = System.BitConverter.GetBytes(byTmp.Length);

                    fsReg.Write(byLen, 0, byLen.Length);
                    fsReg.Write(byTmp, 0, byTmp.Length);
                }
            }
        }