public override string GetDirectUrl(string bucket, string key, TimeSpan expriationDuration)
        {
            string[] strArray = key.Split('/');
            for (int index = 0; index < strArray.Length; ++index)
            {
                strArray[index] = V4Connection.UrlEncode(strArray[index], false);
            }
            key = string.Join("/", strArray);
            SortedList <string, string> query = new SortedList <string, string>()
            {
                {
                    "X-Amz-Expires",
                    expriationDuration.TotalSeconds.ToString()
                }
            };
            StringBuilder stringBuilder = new StringBuilder(Utils.buildUrlBase(this.isSecure, this.server, this.port, bucket, this.callingFormat));

            stringBuilder.Append(key);
            string stringedQuery;
            string signature;
            string headerNames;
            string credential;

            this.GetAuthStuf(new Uri(stringBuilder.ToString()), "GET", query, (IDictionary <string, string>) new Dictionary <string, string>(), "UNSIGNED-PAYLOAD", out stringedQuery, true, out signature, out headerNames, out credential);
            stringBuilder.Append("?").Append(stringedQuery).Append("&").Append("X-Amz-Signature").Append("=").Append(signature);
            return(stringBuilder.ToString());
        }
        private void GetAuthStuf(Uri endpointUri, string method, SortedList <string, string> query, IDictionary <string, string> headers, string bodyHash, out string stringedQuery, bool signedInQuery, out string signature, out string headerNames, out string credential)
        {
            DateTime utcNow  = DateTime.UtcNow;
            string   str1    = utcNow.ToString("yyyyMMddTHHmmssZ", (IFormatProvider)CultureInfo.InvariantCulture);
            string   datestr = utcNow.ToString("yyyyMMdd");
            string   str2    = string.Format("{0}/{1}/{2}/{3}", (object)datestr, (object)this.region, (object)this.service, (object)"aws4_request");
            string   str3    = endpointUri.Host;

            if (!endpointUri.IsDefaultPort)
            {
                str3 = str3 + ":" + (object)endpointUri.Port;
            }
            headers.Add("Host", str3);
            if (!signedInQuery)
            {
                headers.Add("x-amz-date", str1);
            }
            headerNames = this.CanonicalizeHeaderNames(headers);
            credential  = string.Format("{0}/{1}", (object)this.awsAccessKeyId, (object)str2);
            if (signedInQuery)
            {
                query.Add("X-Amz-Algorithm", "AWS4-HMAC-SHA256");
                query.Add("X-Amz-Credential", credential);
                query.Add("X-Amz-SignedHeaders", headerNames);
                query.Add("X-Amz-Date", str1);
            }
            stringedQuery = query == null || query.Count < 1 ? string.Empty : string.Join("&", query.OrderBy <KeyValuePair <string, string>, string>((Func <KeyValuePair <string, string>, string>)(kv => kv.Key), (IComparer <string>)StringComparer.Ordinal).Select <KeyValuePair <string, string>, string>((Func <KeyValuePair <string, string>, string>)(kv => string.Format("{0}={1}", (object)kv.Key, (object)V4Connection.UrlEncode(kv.Value, false)))));
            byte[]        canonicalRequestHash = this.getCanonicalRequestHash(endpointUri, method, stringedQuery, headerNames, this.CanonicalizeHeaders(headers), bodyHash);
            StringBuilder stringBuilder        = new StringBuilder();

            stringBuilder.AppendFormat("{0}\n{1}\n{2}\n", (object)"AWS4-HMAC-SHA256", (object)str1, (object)str2);
            stringBuilder.Append(V4Connection.ToHexString(canonicalRequestHash, true));
            signature = V4Connection.ToHexString(this.getSigningKey(datestr, stringBuilder.ToString()), true);
        }
 private string GetContentHash(Stream contentStream)
 {
     contentStream.Position = 0L;
     using (HashAlgorithm hashAlgorithm = HashAlgorithm.Create("SHA-256"))
         return(V4Connection.ToHexString(hashAlgorithm.ComputeHash(contentStream), true));
 }