public static LicenseRequest FromOfflineData(string data) { using (var memoryStream = new MemoryStream(DataEncoder.FromHexString(data))) { using (var reader = new BinaryReader(memoryStream)) { var header = reader.ReadByte(); var type = (RequestType)(header >> 7); var cidLength = header ^ (byte)type << 7; var request = new LicenseRequest(type) { ClientId = reader.ReadBytes(cidLength) }; if (type == RequestType.Activate) { request.Certificate = reader.ReadBytes(reader.ReadUInt16()); if (memoryStream.Position < memoryStream.Length - 66 /*UInt32+SHA512*/) { var licenseLength = reader.ReadUInt16(); if (licenseLength > 0) { request.LicenseKey = reader.ReadBytes(licenseLength); } } else { request.LicenseKey = new byte[0]; } } var dataEnd = memoryStream.Position; var sign = reader.ReadBytes(64); //Verify sign memoryStream.Position = 0; var databuffer = reader.ReadBytes((int)dataEnd); var signBuffer = RSASigner.GetSignBuffer(databuffer, new[] { HashSecret.GetSecret() }); var signToValidate = SHA512.Create().ComputeHash(signBuffer); if (sign.Where((t, i) => t != signToValidate[i]).Any()) { throw new LicenseValidationException("Signatures doesn't match"); } return(request); } } }
public static LicenseResult FromOfflineString(string offlineString, Client client) { return(new LicenseResult(DataEncoder.FromHexString(offlineString), client)); }