Пример #1
0
        /// <summary>
        /// 检查文件签名
        /// </summary>
        /// <param name="li"></param>
        /// <returns></returns>
        private static Boolean CheckFileSign(LicenseInfo li)
        {
            if (li == null)
            {
                return(false);
            }
            //未启用该限制
            if (!li.FileSignature.Enable)
            {
                return(true);
            }
            if (String.IsNullOrEmpty(li.FileSignature.Value))
            {
                return(false);
            }
            // 获取授权文件路径
            string path = typeof(License).Module.FullyQualifiedName;
            // 读取授权文件
            string filepath = Path.GetDirectoryName(path) + @"\XCode.dll";

            Byte[] bts;
            using (FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read))
            {
                bts = new Byte[fs.Length];
                fs.Read(bts, 0, bts.Length);
                fs.Close();
            }

            if (!Verify(bts, li.FileSignature, PublicKey))
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        internal static void MakeTrail(String filepath)
        {
            LicenseInfo info = LicenseInfo.Trial;

            info.ReadHardInfo();
            //写入当前URL
            if (HttpContext.Current != null)
            {
                info.WebSiteList.Enable = true;
                info.WebSiteList        = HttpContext.Current.Request.Url.ToString();
            }
            String path = GetPath();

            path = Path.Combine(path, "XCode.dll");
            if (File.Exists(path))
            {
                info.FileSignature.Enable = true;
                Byte[] data = File.ReadAllBytes(path);
                if (data != null)
                {
                    MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
                    data = md5.ComputeHash(data);
                    info.FileSignature = Convert.ToBase64String(data);
                }
            }
            String content = info.ToXML();

            //Byte[] bts = Encrypt(Encoding.UTF8.GetBytes(content), InternalKey);
            content = Encode(content);
            Byte[] bts = Encoding.UTF8.GetBytes(content);
            //content = Convert.ToBase64String(bts);
            //using (StreamWriter sw = new StreamWriter(filepath, false, Encoding.UTF8))
            //{
            //    sw.Write(content);
            //    sw.Close();
            //}
            using (FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write))
            {
                fs.Write(bts, 0, bts.Length);
                fs.SetLength(bts.Length);
            }
        }
Пример #3
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static LicenseInfo FromXML(String xml)
        {
            if (String.IsNullOrEmpty(xml))
            {
                return(null);
            }
            try
            {
                XmlDocument Doc = new XmlDocument();
                Doc.LoadXml(xml);

                LicenseInfo li = new LicenseInfo();

                foreach (String item in li.Items.Keys)
                {
                    li.Items[item].FromXml(Doc, item);
                }

                return(li);
            }
            catch { return(null); }
        }
Пример #4
0
        /// <summary>
        /// 读取授权。如果成功,则返回授权;否则返回试用授权。
        /// 不需要建立文件监视,因为如果授权文件改变,程序域将会重启。
        /// </summary>
        /// <returns></returns>
        private static LicenseInfo GetLicense()
        {
            try
            {
                String key = ReadLicense();
                //无法读出授权信息,以试用版方式运行。
                if (String.IsNullOrEmpty(key))
                {
                    _Current = LicenseInfo.Trial;
                    return(_Current);
                }

                String xml = Decode(key);
                if (String.IsNullOrEmpty(xml))
                {
                    ShowErr("非法授权文件!");
                    _Current = LicenseInfo.Trial;
                    return(_Current);
                }
                _Current = LicenseInfo.FromXML(xml);

                //马上检查文件签名授权
                if (!CheckFileSign(_Current))
                {
                    ShowErr("本授权只针对特定版本的XCode,请不要使用其它版本的XCode!");
                    _Current = LicenseInfo.Trial;
                }
            }
            catch (Exception ex)
            {
                XTrace.WriteLine(ex.ToString());
                _Current = LicenseInfo.Trial;
            }
            //放在后面返回,任何错误时都能将其设置为试用版。
            return(_Current);
        }
Пример #5
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static LicenseInfo FromXML(String xml)
        {
            if (String.IsNullOrEmpty(xml)) return null;
            try
            {
                XmlDocument Doc = new XmlDocument();
                Doc.LoadXml(xml);

                LicenseInfo li = new LicenseInfo();

                foreach (String item in li.Items.Keys)
                {
                    li.Items[item].FromXml(Doc, item);
                }

                return li;
            }
            catch { return null; }
        }
Пример #6
0
        /// <summary>
        /// 检查文件签名
        /// </summary>
        /// <param name="li"></param>
        /// <returns></returns>
        private static Boolean CheckFileSign(LicenseInfo li)
        {
            if (li == null) return false;
            //未启用该限制
            if (!li.FileSignature.Enable) return true;
            if (String.IsNullOrEmpty(li.FileSignature.Value)) return false;
            // 获取授权文件路径
            string path = typeof(License).Module.FullyQualifiedName;
            // 读取授权文件
            string filepath = Path.GetDirectoryName(path) + @"\XCode.dll";
            Byte[] bts;
            using (FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read))
            {
                bts = new Byte[fs.Length];
                fs.Read(bts, 0, bts.Length);
                fs.Close();
            }

            if (!Verify(bts, li.FileSignature, PublicKey)) return false;

            return true;
        }
Пример #7
0
        /// <summary>
        /// 读取授权。如果成功,则返回授权;否则返回试用授权。
        /// 不需要建立文件监视,因为如果授权文件改变,程序域将会重启。
        /// </summary>
        /// <returns></returns>
        private static LicenseInfo GetLicense()
        {
            try
            {
                String key = ReadLicense();
                //无法读出授权信息,以试用版方式运行。
                if (String.IsNullOrEmpty(key))
                {
                    _Current = LicenseInfo.Trial;
                    return _Current;
                }

                String xml = Decode(key);
                if (String.IsNullOrEmpty(xml))
                {
                    ShowErr("非法授权文件!");
                    _Current = LicenseInfo.Trial;
                    return _Current;
                }
                _Current = LicenseInfo.FromXML(xml);

                //马上检查文件签名授权
                if (!CheckFileSign(_Current))
                {
                    ShowErr("本授权只针对特定版本的XCode,请不要使用其它版本的XCode!");
                    _Current = LicenseInfo.Trial;
                }
            }
            catch (Exception ex)
            {
                XTrace.WriteLine(ex.ToString());
                _Current = LicenseInfo.Trial;
            }
            //放在后面返回,任何错误时都能将其设置为试用版。
            return _Current;
        }