/// <summary> /// 校验授权文件 /// </summary> /// <param name="filePath"></param> /// <returns></returns> public bool Check(string filePath, out string message) { bool result = false; message = string.Empty; string content = System.IO.File.ReadAllText(filePath); string[] items = content.Split(new string[] { "+++++=====+++++" }, StringSplitOptions.RemoveEmptyEntries); if (items.Length != 3) { message = "授权文件格式无法识别"; return(false); } string json = items[0]; string sign = items[1]; string publicKeyXml = items[2]; var isVerify = Verify(json, sign, publicKeyXml); if (isVerify == false) { message = "授权文件格式校验未通过"; return(false); } AuthorizeFile af = AuthorizeFile.FromJson(json); if (!af.IsEver) { if (DateTime.Now > af.EndDate || DateTime.Now < af.BeginDate) { message = "应用授权失败,限制使用时间" + af.BeginDate + "至" + af.EndDate + ",当前授权类型为:" + af.AuthorizeType; return(false); } } if (af.Check() == false) { message = "应用授权失败,当前授权类型为:" + af.AuthorizeType; return(false); } else { result = true; } return(result); }
/// <summary> /// 校验授权文件 /// </summary> /// <param name="filePath"></param> /// <returns></returns> public bool Check(string filePath, out string message) { bool result = false; message = string.Empty; string content = System.IO.File.ReadAllText(filePath); string[] items = content.Split(new string[] { "+++++=====+++++" }, StringSplitOptions.RemoveEmptyEntries); if (items.Length != 3) { message = "授权文件格式无法识别"; return(false); } string json = items[0]; string sign = items[1]; string publicKeyXml = items[2]; var fileVersionNo = MD5Helper.GetMD5HashString(publicKeyXml).Substring(0, 6); if (fileVersionNo.Equals(this.VersionNo) == false) { message = "版本识别号有误"; return(false); } var isVerify = Verify(json, sign, publicKeyXml); if (isVerify == false) { message = "授权文件格式校验未通过"; return(false); } AuthorizeFile af = AuthorizeFile.FromJson(json); if (af.Check(this.GetMachineCode()) == false) { message = "应用授权失败,当前授权类型为:" + af.AuthorizeType; System.IO.File.Delete(filePath); return(false); } else { result = true; } return(result); }