예제 #1
0
        public T DecryptCookie <T>(string cookieValue, Dictionary <string, string> parameters)
        {
            T      result            = default(T);
            string strEncCookieValue = string.Empty;
            string strContent        = string.Empty;
            string strSHA1Sign       = string.Empty;
            string strShA1Temp       = string.Empty;

            string[] arrayCookieValue = new string[2];

            try
            {
                if (cookieValue.Length < 40)
                {
                    return(result);
                }
                //  取出签名和密文
                strSHA1Sign       = cookieValue.Substring(0, 40);
                strEncCookieValue = cookieValue.Substring(40);
                //  签名校验
                strShA1Temp = HashEncrypt.SHA1Encrypt(HttpUtility.UrlDecode(strEncCookieValue).Trim() + parameters["hashkey"]);
                if (strSHA1Sign != strShA1Temp)
                {
                    return(result);
                }
                strEncCookieValue = HttpUtility.UrlDecode(strEncCookieValue);
                //  还原成明文
                strContent = RC4Encrypt.Decrypt(strEncCookieValue, parameters["rc4key"], RC4Encrypt.EncoderMode.HexEncoder);
                if (strContent.Length == 0)
                {
                    return(result);
                }

                arrayCookieValue = SerializationUtility.JsonDeserialize3 <string[]>(strContent);
                if (arrayCookieValue != null && arrayCookieValue.Length == 3)
                {
                    if (DateTime.Parse(arrayCookieValue[1]) > DateTime.Now && GetClientIP() == arrayCookieValue[2])
                    {
                        result = SerializationUtility.JsonDeserialize2 <T>(arrayCookieValue[0]);
                        //Cookie有效,则继续延续有效期
                        CookieHelper.SaveCookie <T>(parameters["nodeName"], result);
                    }
                }

                return(result);
            }
            catch
            {
                return(result);
            }
        }
예제 #2
0
        public T DecryptCookie <T>(string cookieValue, Dictionary <string, string> parameters)
        {
            T      result            = default(T);
            string strEncCookieValue = string.Empty;
            string strContent        = string.Empty;
            string strSHA1Sign       = string.Empty;
            string strShA1Temp       = string.Empty;

            try
            {
                if (cookieValue.Length < 40)
                {
                    return(result);
                }
                //  取出签名和密文
                strSHA1Sign       = cookieValue.Substring(0, 40);
                strEncCookieValue = cookieValue.Substring(40);
                //  签名校验
                strShA1Temp = HashEncrypt.SHA1Encrypt(HttpUtility.UrlDecode(strEncCookieValue).Trim() + parameters["hashkey"]);
                if (strSHA1Sign != strShA1Temp)
                {
                    return(result);
                }
                strEncCookieValue = HttpUtility.UrlDecode(strEncCookieValue);
                //  还原成明文
                strContent = RC4Encrypt.Decrypt(strEncCookieValue, parameters["rc4key"], RC4Encrypt.EncoderMode.HexEncoder);
                if (strContent.Length == 0)
                {
                    return(result);
                }

                result = SerializationUtility.JsonDeserialize3 <T>(strContent);

                return(result);
            }
            catch
            {
                return(result);
            }
        }
예제 #3
0
 public T DecryptCookie <T>(string cookieValue, Dictionary <string, string> parameters)
 {
     return(SerializationUtility.JsonDeserialize3 <T>(cookieValue));
 }