示例#1
0
        public static bool TryParse(string tokenText, out RequestToken token)
        {
            token = null;
            if (string.IsNullOrEmpty(tokenText))
            {
                return(false);
            }
            string textToDecypt = HttpUtility.UrlDecode(tokenText);

            string[] vector = null;
            if (!SsoCipher.TryParseVector(textToDecypt, out vector))
            {
                return(false);
            }
            if (vector.Length != 3)
            {
                return(false);
            }
            string   returnUrl = vector[0];
            DateTime timeStamp = Convert.ToDateTime(vector[1]);
            string   seed      = vector[2];

            token = new RequestToken(returnUrl, timeStamp, seed);
            return(true);
        }
示例#2
0
        public static bool TryParse(string tokenText, out ResponseToken token)
        {
            token = null;
            if (string.IsNullOrEmpty(tokenText))
            {
                return(false);
            }
            string textToDecypt = HttpUtility.UrlDecode(tokenText);

            string[] vector = null;
            if (!SsoCipher.TryParseVector(textToDecypt, out vector))
            {
                return(false);
            }
            if (vector.Length != 5)
            {
                return(false);
            }
            string   userId     = vector[0];
            DateTime timeStamp  = Convert.ToDateTime(vector[1]);
            int      expire     = Convert.ToInt32(vector[2]);
            string   seed       = vector[3];
            int      resultCode = Convert.ToInt32(vector[4]);

            token = new ResponseToken(userId, timeStamp, expire, seed, resultCode);
            return(true);
        }
示例#3
0
 public string Encode()
 {
     return(SsoCipher.EncryptVector(
                _userId,
                _timeStamp == default(DateTime)?null:_timeStamp.ToString(),
                _expireDuration.ToString()));
 }
示例#4
0
        public string Encode()
        {
            string encodedText = SsoCipher.EncryptVector(
                _returnUrl,
                _timeStamp == default(DateTime)?null:_timeStamp.ToString(),
                _seed);

            return(HttpUtility.UrlEncode(encodedText));
        }
示例#5
0
        public string Encode()
        {
            string encodedText = SsoCipher.EncryptVector
                                     (_userId,
                                     _timeStamp == default(DateTime) ? null : _timeStamp.ToString(),
                                     _expireDuration.ToString(),
                                     _seed,
                                     _resultCode.ToString());

            return(HttpUtility.UrlEncode(encodedText));
        }
示例#6
0
        private static string NextSeed()
        {
            Random        random = new Random((int)DateTime.Now.Ticks);
            StringBuilder sb     = new StringBuilder();

            for (int i = 0; i < 32; i++)
            {
                int idx = random.Next(0, Constants.SeedChars.Length);
                sb.Append(Constants.SeedChars.Substring(idx, 1));
            }
            sb.Append(Guid.NewGuid().ToString());
            return(Seed = SsoCipher.Hash(sb.ToString()));
        }
示例#7
0
 public static bool TryParse(string text, out SsoTicket ticket)
 {
     ticket = null;
     string[] vector;
     if (!SsoCipher.TryParseVector(text, out vector))
     {
         return(false);
     }
     if (vector.Length != 3)
     {
         return(false);
     }
     ticket                 = new SsoTicket();
     ticket._userId         = vector[0];
     ticket._timeStamp      = Convert.ToDateTime(vector[1]);
     ticket._expireDuration = Convert.ToInt32(vector[2]);
     return(true);
 }