Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="unicode"></param>
        /// <returns></returns>
        public string ToString(bool unicode)
        {
            StringBuilder queryString = new StringBuilder(myQueryString.Count * 12);

            IDictionaryEnumerator e = myQueryString.GetEnumerator();

            while (e.MoveNext())
            {
                queryString.Append((string)e.Key);
                queryString.Append('=');
                queryString.Append(HttpUtility.UrlEncode((string)e.Value));
                queryString.Append('&');
            }
            queryString.Remove(queryString.Length - 1, 1);

            string encryptedQuery = StringEncrypter.Encrypt(queryString.ToString());

            string encodedQuery = HttpUtility.UrlEncode(encryptedQuery);

            if (unicode)
            {
                //Required if we are passing it to JavaScript
                encodedQuery = HttpUtility.UrlEncodeUnicode(encodedQuery);
            }

            return(_pageUrl + "?" + ENCRYPTED_KEY + "=" + encodedQuery);
        }
        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));
        }
Beispiel #3
0
    /// <summary>
    /// ユーザデータをローカルに保存する
    /// </summary>
    public void SaveUserData()
    {
        PlayerPrefs.SetString(Const.UserAccount.USER_ID_KEY, StringEncrypter.EncryptString(m_Data.id));
        PlayerPrefs.SetString(Const.UserAccount.USER_PASS_KEY, StringEncrypter.EncryptString(m_Data.pass));
        PlayerPrefs.SetString(Const.UserAccount.USER_NAME_KEY, m_Data.name);
        PlayerPrefs.SetInt(Const.UserAccount.USER_NUM_KEY, m_Data.num);

        // ユーザーデータUIに適用
        UserAccountUIManager.Instance.SetLoginUser();
    }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
0
 /// <summary>
 /// 生成授权码
 /// </summary>
 /// <param name="regCode">注册码</param>
 /// <param name="expire">过期时间</param>
 /// <returns></returns>
 public string GenerateLicense(string regCode = null, DateTime expire = default(DateTime))
 {
     try
     {
         var expireDateTime = expire.ToBinary() > 0 ? expire : DefaultExpireDateTime;
         return(StringEncrypter.Encrypt(YusDate.DateTimeToUnix(expireDateTime) + "_" + (regCode ?? RegCode).Trim()));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(null);
     }
 }
Beispiel #7
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));
     }
 }
Beispiel #8
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);
     }
 }
Beispiel #9
0
        public override void OnEnd(AssemblyDef assembly)
        {
            if (StringEncrypter != null)
            {
                StringEncrypter.Terminate();
                StringEncrypter.Dispose();
            }

            if (ValueEncrypter != null)
            {
                ValueEncrypter.Terminate();
                ValueEncrypter.Dispose();
            }
        }
Beispiel #10
0
        public override void OnBegin(AssemblyDef assembly)
        {
            Logger.Write("DES crypter {0}", assembly.Framework);

            if (StringEncrypter != null)
            {
                StringEncrypter.MergeDecryptionCode(assembly);
            }

            if (ValueEncrypter != null)
            {
                ValueEncrypter.MergeDecryptionCode(assembly);
            }
        }
Beispiel #11
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);
     }
 }
Beispiel #12
0
    /// <summary>
    /// ローカルのユーザーデータをロード
    /// </summary>
    public void LoadUserData()
    {
        string ID   = PlayerPrefs.GetString(Const.UserAccount.USER_ID_KEY);
        string PASS = PlayerPrefs.GetString(Const.UserAccount.USER_PASS_KEY);

        if (ID != "")
        {
            ID = StringEncrypter.DecryptString(ID).Substring(0, 8);
        }
        if (PASS != "")
        {
            PASS = StringEncrypter.DecryptString(PASS).Substring(0, 8);
        }

        m_Data.id   = ID;
        m_Data.pass = PASS;
        m_Data.name = PlayerPrefs.GetString(Const.UserAccount.USER_NAME_KEY);
        m_Data.num  = PlayerPrefs.GetInt(Const.UserAccount.USER_NUM_KEY);
    }
Beispiel #13
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);
                }
            }
        }
Beispiel #14
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);
        }