Beispiel #1
0
        /// <summary>
        /// 分页页码解密
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static int PagerNumDecrypt(string content, bool isThrowError = false)
        {
            if (string.IsNullOrEmpty(content))
            {
                return(1);
            }

            /*  try
             * {*/
            int result;
            // 分页解密
            var pagerEncryptKey = ConfigurationManager.AppSettings["PagerEncryptKey"];
            var removeValue     = content.Remove(0, 2);

            removeValue = removeValue.Substring(0, removeValue.Length - 3);
            var tagerRemoveValue = removeValue.Remove(((removeValue.Length - 32) / 2), 32);

            int.TryParse(CryptTools.Decrypt(tagerRemoveValue, pagerEncryptKey, isThrowError), out result);
            return(result);

            /*}
             * catch (Exception)
             * {
             *  return 1;
             * }
             */
        }
Beispiel #2
0
        /// <summary>
        /// 分页页码加密
        /// 页码加密规则如下:
        /// 1.加密/使用对称加密 密钥是web.config的appSetting Key 为PagerEncryptKey的值
        /// 2.混淆/随机生成一个MD5 对使用对称加密后的字符串/2 取中间位置 将MD5插入中间
        /// 3.在首位插入2位随机字母或数字 最后插入3位随机字母或数字
        /// </summary>
        /// <returns></returns>
        public static string PagerNumEncrypt(long num, bool isThrowError = false)
        {
            // 分页加密密钥
            var pagerEncryptKey = ConfigurationManager.AppSettings["PagerEncryptKey"];
            // 对称加密
            var str = CryptTools.Encrypt(num.ToString(CultureInfo.InvariantCulture), pagerEncryptKey, isThrowError);
            // 获取混淆位置
            var startIndex = str.Length / 2;
            // 混淆加密
            var garble = Guid.NewGuid().ToString("N");
            // 加入混淆
            var value = str.Insert(startIndex, garble);

            return(GenerateCheckCode(2)
                   .ToString(CultureInfo.InvariantCulture) + value +
                   GenerateCheckCode(3));
        }