示例#1
0
        public string CalculateSignature(IEnumerable <KeyValuePair <string, string> > items, string appId)
        {
            if (!IDKeyMap.ContainsKey(appId))
            {
                throw new KeyNotFoundException($"ApiKey for AppId {appId} not found.");
            }
            var apiKey = IDKeyMap[appId];

            string arguments = items.Where(x => !String.IsNullOrEmpty(x.Value))
                               .OrderBy(x => x.Key)
                               .Aggregate(new StringBuilder(),
                                          (sb, next) => sb.Append($"&{next.Key}={next.Value}"),
                                          result => result.Append($"&key={apiKey}").ToString().TrimStart('&'));
            var hash      = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(arguments));
            var signature = BitConverter.ToString(hash).Replace("-", string.Empty);

            return(signature);
        }