コード例 #1
0
        public static string GetUserToken(Dictionary <string, string> acl)
        {
            List <string> tokenList = new List <string>();

            foreach (var key in acl.Keys)
            {
                tokenList.Add(string.Format("{1}{0}{2}", _spliter_inner, key, acl[key]));
            }
            var            userToken = string.Join(_spliter_outer.ToString(), tokenList.ToArray());
            SymmetricCrypt crypt     = new SymmetricCrypt(_type);

            return(crypt.Encrypt(userToken, _key, _iv));
        }
コード例 #2
0
        public static Dictionary <string, string> AnalyzeUserToken(string userToken)
        {
            SymmetricCrypt crypt = new SymmetricCrypt(_type);

            userToken = crypt.Decrypt(userToken, _key, _iv);
            var tokenList = userToken.Split(_spliter_outer);

            var dic = new Dictionary <string, string>();

            foreach (var item in tokenList)
            {
                var tmp = item.Split(_spliter_inner);
                if (tmp.Length == 2)
                {
                    dic.Add(tmp[0], tmp[1]);
                }
                else
                {
                    throw new ArgumentException("口令格式错误 - " + item);
                }
            }
            return(dic);
        }