예제 #1
0
        public static string DeTokenize(string token, int maxDays = 14)
        {
            var decoded = Base64StringDecode(token).Split('|');

            long ticks;

            if (!long.TryParse(decoded[0], out ticks))
            {
                return(null);
            }

            if (Math.Abs((DateTime.UtcNow - new DateTime(ticks)).TotalDays) > maxDays)
            {
                throw new TokenExpiredException();
            }

            return(Aes256Encryption.DecryptString(decoded[1], CreateKey(decoded[0])));
        }
예제 #2
0
        public static string Tokenize(string args)
        {
            var ticks = DateTime.UtcNow.Ticks.ToString();

            return(Base64StringEncode(ticks + "|" + Aes256Encryption.Encrypt(args, CreateKey(ticks))));
        }
예제 #3
0
        private static byte[] CreateKey(string t)
        {
            var seed = int.Parse(MaxLength(t, 9));

            return(Aes256Encryption.CreateKey(seed));
        }