Пример #1
0
        public static string GetPublicKey()
        {
            string text = HiCache.Get("FileCache-Publickey") as string;

            if (string.IsNullOrEmpty(text))
            {
                HttpContext current = HttpContext.Current;
                string      text2;
                if (current != null)
                {
                    text2 = current.Request.MapPath("~/config/publickey.xml");
                }
                else
                {
                    text2 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config\\publickey.xml");
                }
                text = File.ReadAllText(text2);
                HiCache.Max("FileCache-Publickey", text, new CacheDependency(text2));
            }
            return(text);
        }
Пример #2
0
 public static void Insert(string key, object obj, int seconds, CacheItemPriority priority)
 {
     HiCache.Insert(key, obj, null, seconds, priority);
 }
Пример #3
0
 public static void Insert(string key, object obj, CacheDependency dep, int seconds)
 {
     HiCache.Insert(key, obj, dep, seconds, CacheItemPriority.Normal);
 }
Пример #4
0
 public static void Insert(string key, object obj, int seconds)
 {
     HiCache.Insert(key, obj, null, seconds);
 }
Пример #5
0
 public static void Insert(string key, object obj, CacheDependency dep)
 {
     HiCache.Insert(key, obj, dep, 8640);
 }
Пример #6
0
 public static void Insert(string key, object obj)
 {
     HiCache.Insert(key, obj, null, 1);
 }
Пример #7
0
 public static void Max(string key, object obj)
 {
     HiCache.Max(key, obj, null);
 }
Пример #8
0
        public static bool CheckCopyright()
        {
            HttpContext current     = HttpContext.Current;
            XmlDocument xmlDocument = HiCache.Get(CacheCopyrightKey) as XmlDocument;

            bool result;

            if (xmlDocument == null)
            {
                string licenseFile;

                if (current != null)
                {
                    licenseFile = current.Request.MapPath("~/config/ecshop.lics");
                }
                else
                {
                    licenseFile = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ecshop.lics");
                }

                if (!File.Exists(licenseFile))
                {
                    result = false;
                    return(result);
                }

                string license = "";

                try
                {
                    string text = File.ReadAllText(licenseFile);

                    license = HiCryptographer.Decrypt(text);
                }
                catch
                {
                    return(false);
                }

                if (string.IsNullOrWhiteSpace(license))
                {
                    return(false);
                }

                xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(license);

                HiCache.Max(CacheCopyrightKey, xmlDocument, new CacheDependency(licenseFile));
            }

            XmlNode hostNode        = xmlDocument.DocumentElement.SelectSingleNode("//Host");
            XmlNode licenseDateNode = xmlDocument.DocumentElement.SelectSingleNode("//LicenseDate");
            XmlNode expireDateNode  = xmlDocument.DocumentElement.SelectSingleNode("//ExpiresDate");
            XmlNode signNode        = xmlDocument.DocumentElement.SelectSingleNode("//Signature");
            XmlNode openPCNode      = xmlDocument.DocumentElement.SelectSingleNode("//OpenPC");
            XmlNode openWeixinNode  = xmlDocument.DocumentElement.SelectSingleNode("//OpenWeixin");
            XmlNode openAppNode     = xmlDocument.DocumentElement.SelectSingleNode("//OpenApp");
            XmlNode openWapNode     = xmlDocument.DocumentElement.SelectSingleNode("//OpenWap");
            XmlNode openAliohNode   = xmlDocument.DocumentElement.SelectSingleNode("//OpenAliOH");

            string host = current.Request.Url.Host;

            if (!host.EndsWith(hostNode.InnerText))
            //if (string.Compare(hostNode.InnerText, host, true, System.Globalization.CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            else
            {
                string data = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                            "Host={0}&LicenseDate={1:yyyy-MM-dd}&ExpiresDate={2:yyyy-MM-dd}&Key={3}&OpenPC={4}&OpenWeixin={5}&OpenApp={6}&OpenWap={7}&OpenAliOH={8}",
                                            hostNode.InnerText, licenseDateNode.InnerText, expireDateNode.InnerText, LicenseHelper.GetSiteHash(),
                                            openPCNode.InnerText, openWeixinNode.InnerText, openAppNode.InnerText, openWapNode.InnerText, openAliohNode.InnerText);

                bool flag = false;
                using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
                {
                    rsa.FromXmlString(LicenseHelper.GetPublicKey());

                    RSAPKCS1SignatureDeformatter deformatter = new RSAPKCS1SignatureDeformatter(rsa);
                    deformatter.SetHashAlgorithm("SHA1");

                    byte[]      rgbSignature = System.Convert.FromBase64String(signNode.InnerText);
                    SHA1Managed sHA1Managed  = new SHA1Managed();

                    byte[] rgbHash = sHA1Managed.ComputeHash(System.Text.Encoding.UTF8.GetBytes(data));
                    flag = deformatter.VerifySignature(rgbHash, rgbSignature);
                }

                result = (flag && System.DateTime.Now < DateTime.Parse(expireDateNode.InnerText));

                if (result)
                {
                    ServiceStatus = true;

                    OpenPC    = openPCNode.InnerText.Equals("1");
                    OpenApp   = openAppNode.InnerText.Equals("1");
                    OpenVshop = openWeixinNode.InnerText.Equals("1");
                    OpenWap   = openWapNode.InnerText.Equals("1");
                    OpenAliOH = openAliohNode.InnerText.Equals("1");
                }
            }

            return(result);
        }