/// <summary> /// 获取当前注册的信息 /// </summary> public void GetRegisterInfo(out string deadline, out string key) { deadline = "unregistered"; key = ""; if (!File.Exists(_keyFilePath)) { return; } string content = File.ReadAllText(_keyFilePath); if (string.IsNullOrWhiteSpace(content)) { return; } string mac1 = ""; string cpuId1 = ""; string type1 = ""; string deadLine1 = ""; string nowDate1 = ""; string md51 = ""; try { KeyActivator activator = new KeyActivator(); List <string> contentList = activator.Activate(content); key = activator.GetKey(content); cpuId1 = contentList[0]; mac1 = contentList[1]; type1 = contentList[2]; deadLine1 = contentList[3]; nowDate1 = contentList[4]; md51 = contentList[5]; } catch (Exception) { return; } deadline = deadLine1; }
private bool Check(string key) { string mac1 = ""; string cpuId1 = ""; string type1 = ""; string deadLine1 = ""; string produceDate1 = ""; string md51 = ""; string other = ""; try { KeyActivator activator = new KeyActivator(); List <string> contentList = activator.Activate(key); cpuId1 = contentList[0]; mac1 = contentList[1]; type1 = contentList[2]; deadLine1 = contentList[3]; produceDate1 = contentList[4]; md51 = contentList[5]; if (contentList.Count == 7) { other = contentList[6]; } } catch (Exception) { return(false); } string md5Content1 = mac1 + cpuId1 + type1 + deadLine1 + produceDate1; SHA1CryptoServiceProvider sha1Cng = new SHA1CryptoServiceProvider(); byte[] contentMd5Bytes1 = sha1Cng.ComputeHash(UtilityEncoding.Gb2312.GetBytes(md5Content1)); string afreshMd5 = UtilityEncoding.Gb2312.GetString(contentMd5Bytes1); if (afreshMd5 != md51) { return(false); } //读取截至日志 DeadLine = deadLine1; IFormatProvider ifp = new CultureInfo("zh-CN", true); long deadLineTime = DateTime.ParseExact(DeadLine, "yyyyMMdd", ifp).Ticks; //读取生产日志 string produceDate = produceDate1; long produceTime = DateTime.ParseExact(produceDate, "yyyyMMdd", ifp).Ticks; //读取授权文件中的上次启动时间。 long lastStartedTime = produceTime; if (!string.IsNullOrWhiteSpace(other)) { lastStartedTime = DateTime.ParseExact(other, "yyyyMMdd", ifp).Ticks; } //读取本机当前的时间。 long curTime = DateTime.Now.Ticks; if (curTime < deadLineTime && produceTime < curTime && lastStartedTime < curTime && produceTime <= lastStartedTime) { return(true); } return(false); }