Пример #1
0
        public void EncryptAndThenDecryptText_ResultShouldBeEqualToInputText(string inputText)
        {
            var encryptedText = StringEncrypter.Encrypt(testKey, inputText);

            var decryptedText = StringEncrypter.Decrypt(testKey, encryptedText);

            Assert.That(encryptedText, Is.Not.EqualTo(inputText));
            Assert.That(decryptedText, Is.EqualTo(inputText));
        }
Пример #2
0
        public void Encrypt_ShouldReturnSameDataAfterEncryptionAndDecrytion1()
        {
            string tmp      = StringEncrypter.Encrypt("EddyAppels", "aaa");
            string expected = StringEncrypter.Decrypt(tmp, "aaa");

            string tmp2   = StringEncrypter.Encrypt("EddyAppels", "bbb");
            string actual = StringEncrypter.Decrypt(tmp2, "bbb");

            Assert.Equal(expected, actual);
        }
Пример #3
0
        public void Encrypt_ShouldReturnSameDataAfterEncryptionAndDecrytion(string data, string password)
        {
            string tmp      = StringEncrypter.Encrypt(data, password);
            string expected = StringEncrypter.Decrypt(tmp, password);

            string tmp2   = StringEncrypter.Encrypt(data, password);
            string actual = StringEncrypter.Decrypt(tmp2, password);

            Assert.Equal(expected, actual);
        }
Пример #4
0
 /// <summary>
 /// 获取授权码的过期时间
 /// </summary>
 /// <param name="licence">授权码</param>
 /// <returns></returns>
 public DateTime ExpireDateTime(string licence)
 {
     try
     {
         var licInfo  = StringEncrypter.Decrypt(licence);
         var licInfos = licInfo.Split('_');
         return(YusDate.UnixToDate(Convert.ToInt64(licInfos[0])));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(default(DateTime));
     }
 }
Пример #5
0
 /// <summary>
 /// 获取授权码的过期时间戳
 /// </summary>
 /// <param name="licence">授权码</param>
 /// <returns></returns>
 public long ExpireStamp(string licence)
 {
     try
     {
         var licInfo  = StringEncrypter.Decrypt(licence);
         var licInfos = licInfo.Split('_');
         return(Convert.ToInt64(licInfos[0]));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(0);
     }
 }
Пример #6
0
 /// <summary>
 /// 授权码是否已过期
 /// </summary>
 /// <param name="license">授权码</param>
 /// <param name="regCode">注册码</param>
 /// <returns></returns>
 public bool IsLicenseExpire(string license = null, string regCode = null)
 {
     try
     {
         regCode = (regCode ?? RegCode).Trim();
         license = license ?? ReadLicense(DefaultLicenseFilename);
         var licInfo    = StringEncrypter.Decrypt(license);
         var licInfos   = licInfo.Split('_');
         var expireDate = ExpireDateTime(license);
         return(DateTime.Now <= expireDate && licInfos[1] == regCode);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(false);
     }
 }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="queryString"></param>
        private void Parse(string queryString)
        {
            string[] parts = queryString.Split('&');

            foreach (string part in parts)
            {
                int equalToPosition = part.IndexOf('=');

                string name = part.Substring(0, equalToPosition);
                string val  = part.Substring(equalToPosition + 1);
                val = HttpUtility.UrlDecode(val);

                if (name == ENCRYPTED_KEY)
                {
                    if (val.Length > 0)
                    {
                        string decryptedString = HttpUtility.UrlDecode(StringEncrypter.Decrypt(val));

                        string[] keyValue = decryptedString.Split('&');

                        for (int i = 0; i < keyValue.Length; i++)
                        {
                            string param = keyValue[i];
                            equalToPosition = param.IndexOf('=');

                            if (equalToPosition > 0)
                            {
                                string paramName  = param.Substring(0, equalToPosition);
                                string paramValue = param.Substring(equalToPosition + 1);

                                myQueryString.Add(paramName, paramValue);
                            }
                        }
                    }
                }
                else
                {
                    myQueryString.Add(name, val);
                }
            }
        }
Пример #8
0
        public static Dictionary <string, string> GetStartEventList()
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            try
            {
                Settings @default   = Settings.Default;
                Type     type       = @default.GetType();
                string   connection = Settings.Default.heroesConnectionString;
                foreach (PropertyInfo propertyInfo in type.GetProperties())
                {
                    bool flag = false;
                    if (propertyInfo.Name.Equals("heroesConnectionString"))
                    {
                        string crypt = propertyInfo.GetValue(@default, null) as string;
                        foreach (SpecialSettingAttribute specialSettingAttribute in propertyInfo.GetCustomAttributes(typeof(SpecialSettingAttribute), false))
                        {
                            if (specialSettingAttribute.SpecialSetting == SpecialSetting.ConnectionString)
                            {
                                connection = StringEncrypter.Decrypt(crypt, propertyInfo.Name, false);
                                flag       = true;
                                break;
                            }
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                }
                using (EventLoaderDataContext eventLoaderDataContext = new EventLoaderDataContext(connection))
                {
                    DateTime now = DateTime.Now;
                    List <EventGetResult>          list         = new List <EventGetResult>();
                    ISingleResult <EventGetResult> singleResult = eventLoaderDataContext.EventGet();
                    foreach (EventGetResult eventGetResult in singleResult)
                    {
                        if (eventGetResult.StartTime == null && !(eventGetResult.StartCount > 0))
                        {
                            if (eventGetResult.EndTime == null || now < eventGetResult.EndTime)
                            {
                                list.Add(eventGetResult);
                            }
                        }
                        else if (eventGetResult.StartTime != null && now >= eventGetResult.StartTime && (eventGetResult.EndTime == null || now < eventGetResult.EndTime))
                        {
                            if (eventGetResult.PeriodBegin == null)
                            {
                                list.Add(eventGetResult);
                            }
                            else if (now.TimeOfDay >= eventGetResult.PeriodBegin && (eventGetResult.PeriodEnd == null || now.TimeOfDay < eventGetResult.PeriodEnd))
                            {
                                list.Add(eventGetResult);
                            }
                        }
                    }
                    foreach (EventGetResult eventGetResult2 in list)
                    {
                        if (eventGetResult2.Feature != null && eventGetResult2.Feature.Length > 0)
                        {
                            char[] separator = new char[]
                            {
                                ';'
                            };
                            string[] array = eventGetResult2.Feature.Split(separator);
                            for (int k = 0; k < array.Length; k++)
                            {
                                string text  = array[k];
                                string value = "0";
                                int    num   = array[k].IndexOf('[');
                                int    num2  = array[k].IndexOf(']');
                                if (num != -1 && num2 != -1 && num2 > num)
                                {
                                    text  = array[k].Substring(0, num);
                                    value = array[k].Substring(num + 1, num2 - num - 1);
                                }
                                if (text != null && text.Length > 0)
                                {
                                    if (dictionary.ContainsKey(text))
                                    {
                                        dictionary[text] = value;
                                    }
                                    else
                                    {
                                        dictionary.Add(text, value);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log <EventLoader> .Logger.Error("EventLoader load failed", ex);

                throw new InvalidOperationException("EventLoader load failed", ex);
            }
            return(dictionary);
        }