Exemple #1
0
        public static bool IsValidLicense(string licenseXml, string publicKey)
        {
            licenseXml = LicenseHelper.FormatXml(licenseXml);
            int start = licenseXml.IndexOf("<signature>");
            int end   = licenseXml.IndexOf("</signature>") + "</signature>".Length;

            int    sigValueStart = start + "<signature>".Length;
            int    sigValueEnd   = end - "</signature>".Length;
            string signature     = licenseXml.Substring(sigValueStart, sigValueEnd - sigValueStart);

            licenseXml = licenseXml.Substring(0, start) + "<signature />" + licenseXml.Substring(end);
            licenseXml = LicenseHelper.FormatXml(licenseXml);

            return(LicenseHelper.VerifySignature(licenseXml, signature, publicKey));
        }
        internal static bool IsLicenceValid(string publicKey, string licenseText)
        {
            licenseText = Slyce.Common.Utility.StandardizeLineBreaks(licenseText, Slyce.Common.Utility.LineBreaks.Unix).Replace("\n", "");
            int    start            = licenseText.ToLower().IndexOf("<signature>");
            int    end              = licenseText.ToLower().IndexOf("</signature>") + "</signature>".Length;
            string digitalSignature = licenseText.Substring(start + "<signature>".Length, end - start - "<signature>".Length - "</signature>".Length);

            licenseText = licenseText.Substring(0, start) + "<signature />" + licenseText.Substring(end);
            //XmlDocument doc = new XmlDocument();
            //doc.LoadXml(licenseText);
            string rawXml = LicenseHelper.FormatXml(licenseText);

            //string rawXml = doc.InnerXml;//.Substring(doc.InnerXml.IndexOf(">") + 1);
            //rawXml = rawXml.Substring(rawXml.IndexOf(@"?>") + 1).Replace("  ", " ").Replace("\r", "").Replace("\n", "").Replace("\t", "");
            //rawXml = rawXml.Replace("  ", " ").Replace("\r", "").Replace("\n", "").Replace("\t", "");
            return(Licensing.LicenseHelper.VerifySignature(rawXml, digitalSignature, publicKey));
        }
Exemple #3
0
        public string ToXml(string privateKey)
        {
            string xml = string.Format(@"<slyce-license version=""{0}"">
								<product>{1}</product>
								<license serial=""{2}"" type=""{3}"" hardware-id=""{4}"" expiry-date=""{5}"" quantity=""{6}"" />
								<order reference=""{7}"" date=""{8}"">
									<purchaser company=""{9}"" name=""{10}"" email=""{11}"" phone=""{12}"">
										<address line1=""{13}"" line2=""{14}"" city=""{15}"" country=""{16}"" />
									</purchaser>
								</order>
								<signature />
							</slyce-license>"                            ,
                                       Version,
                                       Product,
                                       Serial,
                                       Type,
                                       HardwareId,
                                       ExpiryDate.ToString("d MMM yyyy"),
                                       Quantity,
                                       OrderReference,
                                       OrderDate,
                                       Company,
                                       Name,
                                       Email,
                                       Phone,
                                       AddressLine1,
                                       AddressLine2,
                                       AddressCity,
                                       AddressCountry);

            xml = LicenseHelper.FormatXml(xml);
            string signature = LicenseHelper.CreateSignature(xml.Substring(xml.IndexOf(@"?>") + 2).Replace("<signature />", "").Replace("  ", " ").Replace("\r", "").Replace("\n", "").Replace("\t", ""), privateKey);

            xml = xml.Replace("<signature />", "<signature>" + signature + "</signature>");
            return(LicenseHelper.FormatXml(xml));
        }