/// <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)); }
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); }
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); }
/// <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); } }