using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;namespace BLL
{
    public class stringBLL
    {
        //对密码进行加密时附加的后缀字符
        private string PassExt = "TY";        /// <summary>
        /// 过滤SQL注入字符
        /// </summary>
        /// <param name="Str">要过滤的字符串</param>
        /// <returns></returns>
        #region 过滤SQL注入字符
        public string SqlEncode(string Str)
        {
            return SqlEncode(Str, 0);
        }
        /// <param name="Mode">过滤模式:0全部过滤,1过滤英文,2过滤特殊字符</param>
        public string SqlEncode(string Str, int Mode)
        {
            if (string.IsNullOrEmpty(Str))
                return "";            string SqlStr = "";
            string SqlStr1 = "select|update|delete|insert|drop";
            string SqlStr2 = "'|%|#|<|>|*";
            switch (Mode)
            {
                case 0:
                    SqlStr = SqlStr1 + "|" + SqlStr2;
                    break;
                case 1:
                    SqlStr = SqlStr1;
                    break;
                case 2:
                    SqlStr = SqlStr2;
                    break;
            }
            string[] SqlSplit = SqlStr.Split('|');
            for (int i = 0; i < SqlSplit.Length; i++)
            {
                Str = Str.Replace(SqlSplit[i], "");
            }
            return Str;
        }
        #endregion        /// <summary>
        /// 验证字符是否为数字
        /// </summary>
        /// <param name="Str"></param>
        /// <returns></returns>
        public bool CheckNum(string Str)
        {
            if (string.IsNullOrEmpty(Str))
            {
                return false;
            }            bool Check = false;
            try
            {
                int a = int.Parse(Str);
                Check = true;
            }
            catch
            { }
            return Check;
        }
        public void Show(System.Web.UI.Page page, string msgInfo)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), Guid.NewGuid().ToString(),
                "<script>alert('" + msgInfo + "')</script>");
        }        /// <summary>
        /// 获取字符串左侧字数,按字节数计算
        /// </summary>
        /// <param name="Str">要截取的字符</param>
        /// <param name="Num">要截取的长度</param>
        /// <returns></returns>
        #region 获取字符串左侧字数,按字节数计算
        public string GetLeftStr(string Str, int Len)
        {
            return GetLeftStr(Str, Len, "");
        }
        public string GetLeftStr(string Str, int Len, string Ext)
        {
            string temp = string.Empty;
            if (System.Text.Encoding.Default.GetByteCount(Str) <= Len)//如果长度比需要的长度n小,返回原字符串
            {
                return Str;
            }
            
            int t = 0;
            char[] q = Str.ToCharArray();
            for (int i = 0; i < q.Length && t < Len; i++)
            {
                if ((int)q[i] >= 0x4E00 && (int)q[i] <= 0x9FA5) //是否汉字
                {
                    temp += q[i];
                    t += 2;
                }
                else
                {
                    temp += q[i];
                    t++;
                }
            }
            return (temp + Ext);
            
        }
        #endregion        /// <summary>
        /// 对信息进行html编码处理,防止攻击
        /// </summary>
        /// <param name="Str">要处理的文本信息</param>
        /// <param name="IsAdmin">是否为管理员要进行的操作,如果为管理员操作,对某些特定内容不进行替换</param>
        /// <returns></returns>
        public string HtmlEncode(string Str,bool IsAdmin)
        {
            if (string.IsNullOrEmpty(Str))
            {
                return "";
            }
            Str = Str.Replace("'", "&#39;");
            //Str = Str.Replace("\", "&quot;");
            if (IsAdmin == false)
            {
                Str = System.Text.RegularExpressions.Regex.Replace(Str, @"<script[^>]*?>.*?</script>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                Str = System.Text.RegularExpressions.Regex.Replace(Str, @"<iframe[^>]*?>.*?</iframe>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            }
            return Str;
        }        /// <summary>
        /// 前台用户提交时进行html编码处理,防止攻击
        /// 处理过程使用正则表达式对script等脚本进行处理
        /// </summary>
        /// <param name="Str"></param>
        /// <returns></returns>
        public string UserHtmlEncode(string Str)
        {
            return HtmlEncode(Str, false);
        }        /// <summary>
        /// 对编码过的文本信息进行解码处理,用于编辑
        /// </summary>
        /// <param name="Str">要解码的文本信息</param>
        /// <returns></returns>
        public string HtmlDecode(string Str)
        {
            Str = Str.Replace("'", "&#39;");
            Str = Str.Replace("\"", "&quot;");
            Str = Str.Replace("&", "&amp;");
            Str = Str.Replace("<", "&lt;");
            Str = Str.Replace(">", "&gt;");
            return "";
        }        /// <summary>
        /// 对密码进行MD5加密
        /// </summary>
        /// <param name="Str">明文</param>
        /// <returns>添加密码后缀字符串后的密文</returns>
        public string MD5(string Str)
        {
            return MD5(Str, false);
        }
        /// <param name="Old">是否判断旧密码,旧密码判断不加入密码后缀字符串</param>
        public string MD5(string Str,bool Old)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] bytes = new byte[16];
            System.Text.ASCIIEncoding asc = new System.Text.ASCIIEncoding();
            if (Old == true)
            {
                bytes = md5.ComputeHash(asc.GetBytes(Str));
            }
            else
            {
                bytes = md5.ComputeHash(asc.GetBytes(Str + PassExt));
            }
            return Convert.ToBase64String(bytes);
        }        /// <summary>
        /// 使用SHA1算法求加密
        /// </summary>
        /// <param name="text">明文</param>
        /// <returns>添加密码后缀字符串后的密文</returns>
        public string SHA1(string Str)
        {
            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Str + PassExt, "SHA1");
        }        /// <summary>
        /// 返回脚本类型提示信息,补全javascript代码
        /// </summary>
        /// <param name="Str"></param>
        /// <returns></returns>
        public void ShowMsg(string Msg)
        {
            ShowMsg(Msg, "",false);
        }
        public void ShowMsg(string Msg, bool Back)
        {
            ShowMsg(Msg, "", Back);
        }
        public void ShowMsg(string Msg, string Url)
        {
            ShowMsg(Msg, Url, false);
        }
        public void ShowMsg(string Msg, string Url, bool Back)
        {
            HttpContext.Current.Response.Write(string.Format("<script type=\"text/javascript\">alert('{0}');", Msg));
            if (Url.Length > 0)
            {
                HttpContext.Current.Response.Write(string.Format("window.location='{0}';", Url));
            }
            else
            {
                if (Back == true)
                {
                    HttpContext.Current.Response.Write("history.back();");
                }
            }
            HttpContext.Current.Response.Write("</script>");
        }        public void ShowError(string Msg)
        {
            ShowError(Msg, "");
        }
        public void ShowError(string Msg,string Url)
        {
            HttpContext.Current.Response.Write(string.Format("<script type=\"text/javascript\">alert('{0}');", Msg));
            if (Url.Length > 0)
            {
                HttpContext.Current.Response.Write("window.location='" + Url + "';");
            }
            else
            {
                HttpContext.Current.Response.Write("history.back();");
            }
            HttpContext.Current.Response.Write("</script>");
        }
    }
}我只懂得HTML,这个看不懂
最后出来的密码是sWm7vu4iJUdazAsD5PRaLw==这样的BASE64
具体流程是怎样的呢,我最后没看到有BASE64的计算啊