Exemple #1
0
        public static LicenseEntity ParseLicenseFromBASE64String(Type licenseObjType, string licenseString, byte[] certPubKeyData, out LicenseStatus licStatus,
                                                                 out string validationMsg)
        {
            validationMsg = string.Empty;
            licStatus     = LicenseStatus.UNDEFINED;

            if (string.IsNullOrWhiteSpace(licenseString))
            {
                licStatus = LicenseStatus.CRACKED;
                return(null);
            }

            string        _licXML = string.Empty;
            LicenseEntity _lic    = null;

            try
            {
                //Get RSA key from certificate
                X509Certificate2         cert   = new X509Certificate2(certPubKeyData);
                RSACryptoServiceProvider rsaKey = (RSACryptoServiceProvider)cert.PublicKey.Key;

                XmlDocument xmlDoc = new XmlDocument();

                // Load an XML file into the XmlDocument object.
                xmlDoc.PreserveWhitespace = true;
                xmlDoc.LoadXml(Encoding.UTF8.GetString(Convert.FromBase64String(licenseString)));

                // Verify the signature of the signed XML.
                if (VerifyXml(xmlDoc, rsaKey))
                {
                    XmlNodeList nodeList = xmlDoc.GetElementsByTagName("Signature");
                    xmlDoc.DocumentElement.RemoveChild(nodeList[0]);

                    _licXML = xmlDoc.OuterXml;

                    //Deserialize license
                    XmlSerializer _serializer = new XmlSerializer(typeof(LicenseEntity), new Type[] { licenseObjType });
                    using (StringReader _reader = new StringReader(_licXML))
                    {
                        _lic = (LicenseEntity)_serializer.Deserialize(_reader);
                    }

                    licStatus = _lic.DoExtraValidation(out validationMsg);
                }
                else
                {
                    licStatus = LicenseStatus.INVALID;
                }
            }
            catch (Exception ex)
            {
                licStatus = LicenseStatus.CRACKED;
            }

            return(_lic);
        }
        public static LicenseEntity ParseLicenseFromBase64String(Type licenseObjType, string licenseString,
                                                                 byte[] certPubKeyData, out LicenseStatus licStatus, out string validationMsg)
        {
            validationMsg = string.Empty;
            licStatus     = LicenseStatus.Undefined;

            if (string.IsNullOrWhiteSpace(licenseString))
            {
                licStatus = LicenseStatus.Cracked;
                return(null);
            }

            LicenseEntity lic = null;

            try
            {
                //Get RSA key from certificate
                var cert   = new X509Certificate2(certPubKeyData);
                var rsaKey = (RSACryptoServiceProvider)cert.PublicKey.Key;

                var xmlDoc = new XmlDocument {
                    PreserveWhitespace = true
                };

                // Load an XML file into the XmlDocument object.
                xmlDoc.LoadXml(Encoding.UTF8.GetString(Convert.FromBase64String(licenseString)));

                // Verify the signature of the signed XML.
                if (VerifyXml(xmlDoc, rsaKey))
                {
                    var nodeList = xmlDoc.GetElementsByTagName("Signature");
                    xmlDoc.DocumentElement.RemoveChild(nodeList[0]);

                    string licXml = xmlDoc.OuterXml;

                    //Deserialize license
                    var serializer = new XmlSerializer(typeof(LicenseEntity), new[] { licenseObjType });
                    using (var reader = new StringReader(licXml))
                    {
                        lic = (LicenseEntity)serializer.Deserialize(reader);
                    }

                    licStatus = lic.DoExtraValidation(out validationMsg);
                }
                else
                {
                    licStatus = LicenseStatus.Invalid;
                }
            }
            catch
            {
                licStatus = LicenseStatus.Cracked;
            }

            return(lic);
        }