Пример #1
0
        public string GetStringToSign(CredentialScope scope, HttpRequestMessage request)
        {
            #region Preconditions

            if (scope == null)
            {
                throw new ArgumentNullException(nameof(scope));
            }

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            #endregion

            IEnumerable <string> dateHeaderValues;

            if (!request.Headers.TryGetValues("x-amz-date", out dateHeaderValues))
            {
                throw new Exception("Missing x-amz-date header");
            }

            var timestamp        = dateHeaderValues.First();
            var canonicalRequest = HexString.FromBytes(ComputeSHA256(GetCanonicalRequest(request)));

            return(string.Join("\n",
                               "AWS4-HMAC-SHA256", // Algorithm + \n
                               timestamp,          // Timestamp + \n
                               scope.ToString(),   // Scope     + \n
                               canonicalRequest    // Hex(SHA256(CanonicalRequest))
                               ));
        }
Пример #2
0
        public static string GetStringToSign(
            CredentialScope scope,
            string timestamp,
            string canonicalRequest)
        {
            #region Preconditions

            if (scope == null)
            {
                throw new ArgumentNullException(nameof(scope));
            }

            if (timestamp == null)
            {
                throw new ArgumentNullException(nameof(timestamp));
            }

            if (canonicalRequest == null)
            {
                throw new ArgumentNullException(nameof(canonicalRequest));
            }

            #endregion

            var hashedCanonicalRequest = HexString.FromBytes(ComputeSHA256(canonicalRequest));

            return(string.Join("\n",
                               "AWS4-HMAC-SHA256",    // Algorithm + \n
                               timestamp,             // Timestamp + \n
                               scope.ToString(),      // Scope     + \n
                               hashedCanonicalRequest // Hex(SHA256(CanonicalRequest))
                               ));
        }
Пример #3
0
        public static string GetStringToSign(CredentialScope scope, string timestamp, string canonicalRequest)
        {
            string hashedCanonicalRequest = HexString.FromBytes(ComputeSHA256(canonicalRequest));

            var sb = StringBuilderCache.Aquire();

            sb.AppendJoin('\n', new string[] {
                algorithmName,          // Algorithm + \n
                timestamp,              // Timestamp + \n
                scope.ToString(),       // Scope     + \n
                hashedCanonicalRequest  // Hex(SHA256(CanonicalRequest))
            });

            return(StringBuilderCache.ExtractAndRelease(sb));
        }