Utils.cs
上传用户:xhd1221
上传日期:2022-05-28
资源大小:186k
文件大小:5k
源码类别:

外挂编程

开发平台:

C/C++

  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4. using System.Web;
  5. using System.Security.Cryptography; 
  6. namespace QQWinFarm
  7. {
  8.     public class Utils
  9.     {
  10.         public static string ConvertUnicodeStringToChinese(string unicodeString)
  11.         {
  12.             if (string.IsNullOrEmpty(unicodeString))
  13.                 return string.Empty;
  14.             string outStr = unicodeString;
  15.             Regex re = new Regex("\\u[0123456789abcdef]{4}", RegexOptions.IgnoreCase);
  16.             MatchCollection mc = re.Matches(unicodeString);
  17.             foreach (Match ma in mc)
  18.             {
  19.                 outStr = outStr.Replace(ma.Value, ConverUnicodeStringToChar(ma.Value).ToString());
  20.             }
  21.             return outStr;
  22.         }
  23.         private static char ConverUnicodeStringToChar(string str)
  24.         {
  25.             char outStr = Char.MinValue;
  26.             outStr = (char)int.Parse(str.Remove(0, 2), System.Globalization.NumberStyles.HexNumber);
  27.             return outStr;
  28.         }
  29.         /// <summary> 
  30.         /// md5加密 
  31.         /// </summary> 
  32.         /// <param name="input"></param> 
  33.         /// <returns></returns> 
  34.         public static string getMd5Hash2(string input)
  35.         {
  36.             byte[] buffer = MD5.Create().ComputeHash(Encoding.Default.GetBytes(input));
  37.             StringBuilder builder = new StringBuilder();
  38.             for (int i = 0; i < buffer.Length; i++)
  39.             {
  40.                 builder.Append(buffer[i].ToString("x2"));
  41.             }
  42.             return builder.ToString();
  43.         }
  44.         /// <summary> 
  45.         /// 三次md5加密 
  46.         /// </summary> 
  47.         /// <param name="input"></param> 
  48.         /// <returns></returns> 
  49.         public static string getMd5Hash(string input)
  50.         {
  51.             MD5 md = MD5.Create();
  52.             byte[] buffer = md.ComputeHash(Encoding.Default.GetBytes(input));
  53.             buffer = md.ComputeHash(buffer);
  54.             buffer = md.ComputeHash(buffer);
  55.             StringBuilder builder = new StringBuilder();
  56.             for (int i = 0; i < buffer.Length; i++)
  57.             {
  58.                 builder.Append(buffer[i].ToString("x2"));
  59.             }
  60.             return builder.ToString();
  61.         }
  62.         ////   <summary>   
  63.         ///   去除HTML标记   
  64.         ///   </summary>   
  65.         ///   <param   name="NoHTML">包括HTML的源码   </param>   
  66.         ///   <returns>已经去除后的文字</returns>   
  67.         public static string NoHTML(string Htmlstring)
  68.         {
  69.             //删除脚本   
  70.             Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
  71.             //删除HTML   
  72.             Regex regex = new Regex("<.+?>", RegexOptions.IgnoreCase);
  73.             Htmlstring = regex.Replace(Htmlstring, "");
  74.             Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
  75.             Htmlstring = Regex.Replace(Htmlstring, @"([rn])[s]+", "", RegexOptions.IgnoreCase);
  76.             Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
  77.             Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
  78.             Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", """, RegexOptions.IgnoreCase);
  79.             Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
  80.             Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
  81.             Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
  82.             Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", "   ", RegexOptions.IgnoreCase);
  83.             Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "xa1", RegexOptions.IgnoreCase);
  84.             Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "xa2", RegexOptions.IgnoreCase);
  85.             Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "xa3", RegexOptions.IgnoreCase);
  86.             Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "xa9", RegexOptions.IgnoreCase);
  87.             Htmlstring = Regex.Replace(Htmlstring, @"&#(d+);", "", RegexOptions.IgnoreCase);
  88.             Htmlstring.Replace("<", "");
  89.             Htmlstring.Replace(">", "");
  90.             Htmlstring.Replace("rn", "");
  91.             //Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim(); 
  92.             return Htmlstring;
  93.         }
  94.         /// <summary> 
  95.         /// md5加密 
  96.         /// </summary> 
  97.         /// <param name="str"></param> 
  98.         /// <returns></returns> 
  99.         //public string MD5(String str) 
  100.         //{ 
  101.         //    MD5 md5 = new MD5CryptoServiceProvider(); 
  102.         //    byte[] data = System.Text.Encoding.Default.GetBytes(str); 
  103.         //    byte[] result = md5.ComputeHash(data); 
  104.         //    String ret = ""; 
  105.         //    for (int i = 0; i < result.Length; i++) 
  106.         //        ret += result[i].ToString("x").PadLeft(2, '0'); 
  107.         //    return ret; 
  108.         //}  
  109.     }
  110. }