/// <summary> /// 用于处理密码不够或密码过长的处理 /// </summary> /// <param name="encryptKey">原密码密钥</param> /// <param name="length">密码要求长度</param> /// <returns>返回实际密码</returns> public static string GetPassword(string encryptKey, int length) { encryptKey = TextUtility.CutLeft(encryptKey, length); encryptKey = encryptKey.PadRight(length, ' '); return(encryptKey.Substring(0, length)); }
/// <summary> /// 加密 /// </summary> /// <param name="plainText">待加密的文本</param> /// <param name="cipherkey">密钥</param> /// <returns>返回与此实例等效的加密文本</returns> public static string Encrypt(string plainText, string cipherkey) { cipherkey = TextUtility.CutLeft(cipherkey, 32); cipherkey = cipherkey.PadRight(32, ' '); ICryptoTransform transform = new RijndaelManaged { Key = Encoding.UTF8.GetBytes(cipherkey.Substring(0, 32)), IV = Keys }.CreateEncryptor(); byte[] bytes = Encoding.UTF8.GetBytes(plainText); return(Convert.ToBase64String(transform.TransformFinalBlock(bytes, 0, bytes.Length))); }
/// <summary> /// 加密 /// </summary> /// <param name="plainText">待加密的字节</param> /// <param name="cipherkey">密钥</param> /// <returns>返回与此实例等效的加密字节</returns> public static byte[] EncryptBuffer(byte[] plainText, string cipherkey) { cipherkey = TextUtility.CutLeft(cipherkey, 0x20); cipherkey = cipherkey.PadRight(0x20, ' '); RijndaelManaged managed = new RijndaelManaged { Key = Encoding.UTF8.GetBytes(cipherkey.Substring(0, 0x20)), IV = Keys }; return(managed.CreateEncryptor().TransformFinalBlock(plainText, 0, plainText.Length)); }
public static string Encrypt(string encryptString, string encryptKey) { encryptKey = TextUtility.CutLeft(encryptKey, 8); encryptKey = encryptKey.PadRight(8, ' '); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8)); byte[] keys = DES.Keys; byte[] bytes2 = System.Text.Encoding.UTF8.GetBytes(encryptString); System.Security.Cryptography.DESCryptoServiceProvider dESCryptoServiceProvider = new System.Security.Cryptography.DESCryptoServiceProvider(); System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(); System.Security.Cryptography.CryptoStream cryptoStream = new System.Security.Cryptography.CryptoStream(memoryStream, dESCryptoServiceProvider.CreateEncryptor(bytes, keys), System.Security.Cryptography.CryptoStreamMode.Write); cryptoStream.Write(bytes2, 0, bytes2.Length); cryptoStream.FlushFinalBlock(); return(System.Convert.ToBase64String(memoryStream.ToArray())); }
/// <summary> /// DES加密 /// </summary> /// <param name="encryptString">待加密的字符串</param> /// <param name="encryptKey">加密密钥,要求为8位</param> /// <returns>加密成功返回加密后的字符串,失败返回源串</returns> public static string Encrypt(string encryptString, string encryptKey) { encryptKey = TextUtility.CutLeft(encryptKey, 8); encryptKey = encryptKey.PadRight(8, ' '); byte[] bytes = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8)); byte[] keys = Keys; byte[] buffer = Encoding.UTF8.GetBytes(encryptString); var provider = new DESCryptoServiceProvider(); var stream = new MemoryStream(); var stream2 = new CryptoStream(stream, provider.CreateEncryptor(bytes, keys), CryptoStreamMode.Write); stream2.Write(buffer, 0, buffer.Length); stream2.FlushFinalBlock(); return(Convert.ToBase64String(stream.ToArray())); }
/// <summary> /// 获取问题内容 /// </summary> /// <param name="content"></param> /// <returns></returns> protected string GetIssueContent(string content) { string rValue = ""; if (!string.IsNullOrEmpty(content)) { if (content.Length > 30) { rValue = TextUtility.CutLeft(Utility.HtmlDecode(content), 30) + "..."; } else { rValue = Utility.HtmlDecode(content); } } return(rValue); }
/// <summary> /// 解密 /// </summary> /// <param name="cipherText">待解密的字节</param> /// <param name="cipherkey">密钥</param> /// <returns>返回与此实例等效的解密字节</returns> public static byte[] DecryptBuffer(byte[] cipherText, string cipherkey) { try { cipherkey = TextUtility.CutLeft(cipherkey, 32); cipherkey = cipherkey.PadRight(32, ' '); RijndaelManaged managed = new RijndaelManaged { Key = Encoding.UTF8.GetBytes(cipherkey), IV = Keys }; return(managed.CreateDecryptor().TransformFinalBlock(cipherText, 0, cipherText.Length)); } catch { return(null); } }
/// <summary> /// 解密 /// </summary> /// <param name="cipherText">待解密的文本</param> /// <param name="cipherkey">密钥</param> /// <returns>返回与此实例等效的解密文本</returns> public static string Decrypt(string cipherText, string cipherkey) { try { cipherkey = TextUtility.CutLeft(cipherkey, 32); cipherkey = cipherkey.PadRight(32, ' '); ICryptoTransform transform = new RijndaelManaged { Key = Encoding.UTF8.GetBytes(cipherkey), IV = Keys }.CreateDecryptor(); byte[] inputBuffer = Convert.FromBase64String(cipherText); byte[] bytes = transform.TransformFinalBlock(inputBuffer, 0, inputBuffer.Length); return(Encoding.UTF8.GetString(bytes)); } catch { return(""); } }
/// <summary> /// DES解密 /// </summary> /// <param name="decryptString">待解密的字符串</param> /// <param name="decryptKey">解密密钥,要求为8位,和加密密钥相同</param> /// <returns>解密成功返回解密后的字符串,失败返源串</returns> public static string Decrypt(string decryptString, string decryptKey) { try { decryptKey = TextUtility.CutLeft(decryptKey, 8); decryptKey = decryptKey.PadRight(8, ' '); byte[] bytes = Encoding.UTF8.GetBytes(decryptKey); byte[] keys = Keys; byte[] buffer = Convert.FromBase64String(decryptString); DESCryptoServiceProvider provider = new DESCryptoServiceProvider(); MemoryStream stream = new MemoryStream(); CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(bytes, keys), CryptoStreamMode.Write); stream2.Write(buffer, 0, buffer.Length); stream2.FlushFinalBlock(); return(Encoding.UTF8.GetString(stream.ToArray())); } catch { return(""); } }
public static string Decrypt(string decryptString, string decryptKey) { string result; try { decryptKey = TextUtility.CutLeft(decryptKey, 8); decryptKey = decryptKey.PadRight(8, ' '); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(decryptKey); byte[] keys = DES.Keys; byte[] array = System.Convert.FromBase64String(decryptString); System.Security.Cryptography.DESCryptoServiceProvider dESCryptoServiceProvider = new System.Security.Cryptography.DESCryptoServiceProvider(); System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(); System.Security.Cryptography.CryptoStream cryptoStream = new System.Security.Cryptography.CryptoStream(memoryStream, dESCryptoServiceProvider.CreateDecryptor(bytes, keys), System.Security.Cryptography.CryptoStreamMode.Write); cryptoStream.Write(array, 0, array.Length); cryptoStream.FlushFinalBlock(); result = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray()); } catch { result = ""; } return(result); }
/// <summary> /// 绑定财富排行 /// </summary> private void BindScoreRank() { StringBuilder builderTopView = new StringBuilder(); StringBuilder builderOtherView = new StringBuilder(); DataSet ds = FacadeManage.aideTreasureFacade.GetScoreRanking(10); DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { if (i < 3) { //前三 builderTopView.AppendFormat("<li><p class=\"ui-rank-face\"><img src=\"{0}\"><i class=\"ui-rank-{1}\"></i></p><p>{2}</p><span>{3}</span></li>", FacadeManage.aideAccountsFacade.GetUserFaceUrl(Convert.ToInt32(dt.Rows[i]["UserID"])), i + 1, TextUtility.CutLeft(dt.Rows[i]["NickName"].ToString(), 5), GetChinaString(Convert.ToInt64(dt.Rows[i]["Score"]))); } else { //其他 builderOtherView.AppendFormat("<li class=\"fn-clear\"><span>{2}</span><strong>{0}</strong><p>{1}</p></li>", i + 1, TextUtility.CutLeft(dt.Rows[i]["NickName"].ToString(), 16), dt.Rows[i]["Score"].ToString()); } } litRank.Text = "<ul class=\"ui-rank-topthree fn-clear\">" + builderTopView.ToString() + "</ul>" + "<ul class=\"ui-rank-list\">" + builderOtherView.ToString() + "</ul>"; } else { litRank.Text = ""; } }
/// <summary> /// 绑定财富排行 /// </summary> private void BindScoreRank() { StringBuilder builderTopView = new StringBuilder(); StringBuilder builderOtherView = new StringBuilder(); RankCache cache = Fetch.GetRankList(2); if (cache != null && cache.CacheList != null) { List <RankInfo> list = cache.CacheList.ToList <RankInfo>(); if (list.Count > 10) { list.RemoveRange(10, (list.Count - 10)); } for (int i = 0; i < list.Count; i++) { RankInfo info = list[i]; if (i < 3) { //前三 builderTopView.AppendFormat("<li><p class=\"ui-rank-face\"><img src=\"{0}\"><i class=\"ui-rank-{1}\"></i></p><p>{2}</p><span>{3}</span></li>", FacadeManage.aideAccountsFacade.GetUserFaceUrl(info.UserID), i + 1, TextUtility.CutLeft(info.NickName, 5), GetChinaString(info.RankValue)); } else { //其他 builderOtherView.AppendFormat("<li class=\"fn-clear\"><span>{2}</span><strong>{0}</strong><p>{1}</p></li>", i + 1, TextUtility.CutLeft(info.NickName, 16), info.RankValue.ToString()); } } litRank.Text = "<ul class=\"ui-rank-topthree fn-clear\">" + builderTopView.ToString() + "</ul>" + "<ul class=\"ui-rank-list\">" + builderOtherView.ToString() + "</ul>"; } else { litRank.Text = ""; } }