public static RegInfo GetKeyInfo(bool bPlain, string keyInfo) { var result = new RegInfo(); string keyInfoPlain = keyInfo; if (!bPlain) { keyInfoPlain = ParseKey(keyInfo); } if (keyInfoPlain.Length < 54) { throw new Exception("注册码无效,注册码长度不够"); } string[] strTemp = keyInfoPlain.Split('*'); if (strTemp.Length < 7) { throw new Exception("注册码无效,注册码信息不完整"); } int nIndex = 0; result.CompanyCode = strTemp[nIndex].ToUpper(); nIndex++; result.CompanyName = strTemp[nIndex].ToUpper(); nIndex++; result.PcSn = strTemp[nIndex].ToUpper(); nIndex++; result.LifeStartTime = new DateTime(long.Parse(strTemp[nIndex])); nIndex++; result.LifeEndTime = new DateTime(long.Parse(strTemp[nIndex])); nIndex++; result.ImportStartTime = new DateTime(long.Parse(strTemp[nIndex])); nIndex++; result.ImportEndTime = new DateTime(long.Parse(strTemp[nIndex])); return result; }
public static ValidResult ValidRegInfo(RegInfo regInfo) { ValidResult result = new ValidResult(); result.RegInfo = regInfo; //验证机器码 List<string> list = GetMachineCode(); bool bFlag = false; foreach (var item in list) { if (!regInfo.PcSn.ToUpper().Equals(item.ToUpper())) { bFlag = true; break; } } if (!bFlag) { result.Message = "非本机器注册码"; return result; } //验证时间 DateTime tmCurrent = DateTime.Now; if (regInfo.LifeEndTime.CompareTo(tmCurrent) < 0) { result.Message = "注册码已经过期"; return result; } if (regInfo.LifeStartTime.CompareTo(tmCurrent) > 0) { result.Message = "注册码尚未生效"; return result; } result.Message = "注册码有效期为:" + result.RegInfo.LifeStartTime.ToString("yyyy-MM-dd hh:mm:ss") + " 至 " + result.RegInfo.LifeEndTime.ToString("yyyy-MM-dd hh:mm:ss"); result.IsValid = true; return result; }
/// <summary> /// 生成注册码 /// </summary> public static string MakeKey(RegInfo regInfo) { string strInput = regInfo.CompanyCode + "*"; strInput += regInfo.CompanyName + "*"; strInput += regInfo.PcSn + "*"; strInput += regInfo.LifeStartTime.Ticks + "*"; strInput += regInfo.LifeEndTime.Ticks + "*"; strInput += regInfo.ImportStartTime.Ticks + "*"; strInput += regInfo.ImportEndTime.Ticks; HKCryptString rsa = new HKCryptString(); return rsa.EnCrypt(strInput); }