コード例 #1
0
        public static string request(string host, SortedDictionary <string, object> parameters, string secret)
        {
            StringBuilder queryString = new StringBuilder();

            foreach (var p in parameters)
            {
                queryString
                .Append(PopEncode.Encode(p.Key)).Append("=")
                .Append(PopEncode.Encode(p.Value.ToString()))
                .Append("&");
            }
            string request = host + "/?" + queryString + "Signature=" + Sign.sign("GET", parameters, secret + "&");

            return(request);
        }
コード例 #2
0
ファイル: Sign.cs プロジェクト: zj935160644/alicloud-ams-demo
        public static string sign(string method, SortedDictionary <string, object> parameters, string secret)
        {
            StringBuilder canonicalizedQueryString = new StringBuilder();

            foreach (var p in parameters)
            {
                canonicalizedQueryString.Append("&")
                .Append(PopEncode.popEncode(p.Key)).Append("=")
                .Append(PopEncode.popEncode(p.Value.ToString()));
            }
            StringBuilder stringToSign = new StringBuilder();

            stringToSign.Append(method.ToString());
            stringToSign.Append(SEPARATOR);
            stringToSign.Append(PopEncode.popEncode("/"));
            stringToSign.Append(SEPARATOR);
            stringToSign.Append(PopEncode.popEncode(
                                    canonicalizedQueryString.ToString().Substring(1)));

            var algorithm = KeyedHashAlgorithm.Create("HMACSHA1");

            algorithm.Key = Encoding.UTF8.GetBytes(secret.ToCharArray());
            return(Convert.ToBase64String(algorithm.ComputeHash(Encoding.UTF8.GetBytes(stringToSign.ToString().ToCharArray()))));
        }