Ejemplo n.º 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);
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
     }
 }