Example #1
0
        /// <summary>
        /// Base64解密
        /// </summary>
        /// <param name="text">要解密的字符串</param>
        public static string DecodeBase64(string text)
        {
            string result = string.Empty;

            try
            {
                //如果字符串为空,则返回
                if (ValidationHelper.IsNullOrEmpty <string>(text))
                {
                    result = string.Empty;
                }

                //将空格替换为加号
                text = text.Replace(" ", "+");

                if ((text.Length % 4) != 0)
                {
                    result = "包含不正确的BASE64编码";
                }
                if (!Regex.IsMatch(text, "^[A-Z0-9/+=]*$", RegexOptions.IgnoreCase))
                {
                    result = "包含不正确的BASE64编码";
                }
                const string base64Code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
                int          page       = text.Length / 4;
                var          outMessage = new ArrayList(page * 3);
                char[]       message    = text.ToCharArray();
                for (int i = 0; i < page; i++)
                {
                    var instr = new byte[4];
                    instr[0] = (byte)base64Code.IndexOf(message[i * 4]);
                    instr[1] = (byte)base64Code.IndexOf(message[i * 4 + 1]);
                    instr[2] = (byte)base64Code.IndexOf(message[i * 4 + 2]);
                    instr[3] = (byte)base64Code.IndexOf(message[i * 4 + 3]);
                    var outstr = new byte[3];
                    outstr[0] = (byte)((instr[0] << 2) ^ ((instr[1] & 0x30) >> 4));
                    if (instr[2] != 64)
                    {
                        outstr[1] = (byte)((instr[1] << 4) ^ ((instr[2] & 0x3c) >> 2));
                    }
                    else
                    {
                        outstr[2] = 0;
                    }
                    if (instr[3] != 64)
                    {
                        outstr[2] = (byte)((instr[2] << 6) ^ instr[3]);
                    }
                    else
                    {
                        outstr[2] = 0;
                    }
                    outMessage.Add(outstr[0]);
                    if (outstr[1] != 0)
                    {
                        outMessage.Add(outstr[1]);
                    }
                    if (outstr[2] != 0)
                    {
                        outMessage.Add(outstr[2]);
                    }
                }
                var outbyte = (byte[])outMessage.ToArray(Type.GetType("System.Byte"));
                result = Encoding.Default.GetString(outbyte);
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageIndex">当前查询页</param>
        /// <param name="pagesize">每页记录集数量</param>
        /// <param name="fdname">用于定位记录的主键(惟一键)字段,可以是逗号分隔的多个字段</param>
        /// <param name="filedName">以逗号分隔的要显示的字段列表,如果不指定,则显示所有字段</param>
        /// <param name="TableName">查询表名</param>
        /// <param name="WhereStr">条件语句(可为空)</param>
        /// <param name="OrderByStr">以逗号分隔的排序字段列表,可以指定在字段后面指定DESC/ASC用于指定排序顺序(可为空)</param>
        /// <param name="pageCount">输出总页数</param>
        /// <param name="recordcount">记录集总数</param>
        /// <returns></returns>
        public static DataTable pageSearch(int pageIndex, int pagesize, string fdname, string filedName, string TableName, string WhereStr, string OrderByStr, out int pageCount, out int recordcount)
        {
            DataTable dt = null;

            pageCount   = 0;
            recordcount = 0;
            try
            {
                DataSet dbs = new DataSet();
                using (SqlConnection SqlConn = new SqlConnection(conStr))
                {
                    if (SqlConn.State != ConnectionState.Open)
                    {
                        SqlConn.Open();
                    }
                    if (pageIndex <= 0)
                    {
                        pageIndex = 1;
                    }
                    using (SqlCommand command = new SqlCommand("proc_ShowPages", SqlConn))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.Add(new SqlParameter("@PageSize", SqlDbType.Int));
                        command.Parameters.Add(new SqlParameter("@PageIndex", SqlDbType.Int));
                        command.Parameters.Add(new SqlParameter("@FieldKey", SqlDbType.VarChar, 8000));
                        command.Parameters.Add(new SqlParameter("@FieldShow", SqlDbType.VarChar, 8000));
                        command.Parameters.Add(new SqlParameter("@TableName", SqlDbType.VarChar, 8000));
                        if (!string.IsNullOrEmpty(WhereStr))
                        {
                            command.Parameters.Add(new SqlParameter("@Where", SqlDbType.VarChar, 8000));
                        }
                        if (!string.IsNullOrEmpty(OrderByStr))
                        {
                            command.Parameters.Add(new SqlParameter("@FieldOrder", SqlDbType.VarChar, 8000));
                        }
                        command.Parameters.Add(new SqlParameter("@TotalCount", SqlDbType.Int));
                        command.Parameters.Add(new SqlParameter("@TotalPageCount", SqlDbType.Int));
                        command.UpdatedRowSource = UpdateRowSource.None;
                        command.Parameters["@PageSize"].Value  = pagesize;
                        command.Parameters["@PageIndex"].Value = pageIndex;
                        command.Parameters["@FieldKey"].Value  = fdname;
                        command.Parameters["@FieldShow"].Value = filedName;
                        command.Parameters["@TableName"].Value = TableName;
                        if (!string.IsNullOrEmpty(WhereStr))
                        {
                            command.Parameters["@Where"].Value = WhereStr;
                        }
                        if (!string.IsNullOrEmpty(OrderByStr))
                        {
                            command.Parameters["@FieldOrder"].Value = OrderByStr;
                        }
                        command.Parameters["@TotalCount"].Direction     = ParameterDirection.Output;
                        command.Parameters["@TotalPageCount"].Direction = ParameterDirection.Output;
                        SqlDataAdapter sda = new SqlDataAdapter();
                        sda.SelectCommand = command;
                        sda.SelectCommand.ExecuteNonQuery();
                        recordcount = int.Parse(sda.SelectCommand.Parameters["@TotalCount"].Value.ToString());
                        pageCount   = int.Parse(sda.SelectCommand.Parameters["@TotalPageCount"].Value.ToString());
                        sda.Fill(dbs, "data");
                    }
                }
                dt = dbs.Tables[0];
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(dt);
        }
Example #3
0
        /// <summary>
        /// Base64加密
        /// </summary>
        /// <param name="text">要加密的字符串</param>
        /// <returns></returns>
        public static string EncodeBase64(string text)
        {
            string result = string.Empty;

            try
            {
                //如果字符串为空,则返回
                if (ValidationHelper.IsNullOrEmpty <string>(text))
                {
                    return("");
                }

                var base64Code = new[]
                {
                    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
                    'Q', 'R', 'S', 'T',
                    'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
                    'k', 'l', 'm', 'n',
                    'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
                    '4', '5', '6', '7',
                    '8', '9', '+', '/', '='
                };
                const byte empty       = 0;
                var        byteMessage = new ArrayList(Encoding.Default.GetBytes(text));
                int        messageLen  = byteMessage.Count;
                int        page        = messageLen / 3;
                int        use;
                if ((use = messageLen % 3) > 0)
                {
                    for (int i = 0; i < 3 - use; i++)
                    {
                        byteMessage.Add(empty);
                    }
                    page++;
                }
                var outmessage = new StringBuilder(page * 4);
                for (int i = 0; i < page; i++)
                {
                    var instr = new byte[3];
                    instr[0] = (byte)byteMessage[i * 3];
                    instr[1] = (byte)byteMessage[i * 3 + 1];
                    instr[2] = (byte)byteMessage[i * 3 + 2];
                    var outstr = new int[4];
                    outstr[0] = instr[0] >> 2;
                    outstr[1] = ((instr[0] & 0x03) << 4) ^ (instr[1] >> 4);
                    if (!instr[1].Equals(empty))
                    {
                        outstr[2] = ((instr[1] & 0x0f) << 2) ^ (instr[2] >> 6);
                    }
                    else
                    {
                        outstr[2] = 64;
                    }
                    if (!instr[2].Equals(empty))
                    {
                        outstr[3] = (instr[2] & 0x3f);
                    }
                    else
                    {
                        outstr[3] = 64;
                    }
                    outmessage.Append(base64Code[outstr[0]]);
                    outmessage.Append(base64Code[outstr[1]]);
                    outmessage.Append(base64Code[outstr[2]]);
                    outmessage.Append(base64Code[outstr[3]]);
                }
                result = outmessage.ToString();
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(result);
        }