private async Task<bool> IsHashValidAsync(HttpContent payload)
        {
            var normalizedPayload = new NormalizedPayload(payload);
            byte[] data = await normalizedPayload.ToBytesAsync();

            return this.hasher.IsValidHash(data, artifacts.PayloadHash);
        }
        private bool IsHashValid(string body, string contentType)
        {
            var normalizedPayload = new NormalizedPayload(body, contentType);
            byte[] data = normalizedPayload.ToBytes();

            bool isHashValid = this.hasher.IsValidHash(data, artifacts.PayloadHash);

            if (!isHashValid)
                Tracing.Information(
                    String.Format("Invalid payload hash {0} for data {1}", artifacts.PayloadHash.ToBase64String(),
                                                                            Encoding.UTF8.GetString(data)));

            return isHashValid;
        }
        /// <summary>
        /// Creates the payload hash and the corresponding HMAC, and updates the artifacts object with these new values.
        /// </summary>
        internal async Task SignAsync(HttpContent newContent)
        {
            byte[] responsePayloadHash = null;
            if (newContent != null)
            {
                var payload = new NormalizedPayload(newContent);
                byte[] data = await payload.ToBytesAsync();

                responsePayloadHash = hasher.ComputeHash(data);
            }

            artifacts.PayloadHash = responsePayloadHash;
            artifacts.Mac = hasher.ComputeHmac(this.normalizedRequest.ToBytes(), credential.Key);
        }
        private async Task<bool> IsHashValidAsync(HttpContent payload)
        {
            var normalizedPayload = new NormalizedPayload(payload);
            byte[] data = await normalizedPayload.ToBytesAsync();

            bool isHashValid = this.hasher.IsValidHash(data, artifacts.PayloadHash);

            if (!isHashValid)
                Tracing.Information(
                    String.Format("Invalid payload hash {0} for data {1}", artifacts.PayloadHash.ToBase64String(),
                                                                            Encoding.UTF8.GetString(data)));

            return isHashValid;
        }
Esempio n. 5
0
        private bool IsHashValid(string body, string contentType)
        {
            var normalizedPayload = new NormalizedPayload(body, contentType);

            byte[] data = normalizedPayload.ToBytes();

            bool isHashValid = this.hasher.IsValidHash(data, artifacts.PayloadHash);

            if (!isHashValid)
            {
                Tracing.Information(
                    String.Format("Invalid payload hash {0} for data {1}", artifacts.PayloadHash.ToBase64String(),
                                  Encoding.UTF8.GetString(data)));
            }

            return(isHashValid);
        }
Esempio n. 6
0
        private async Task <bool> IsHashValidAsync(HttpContent payload)
        {
            var normalizedPayload = new NormalizedPayload(payload);

            byte[] data = await normalizedPayload.ToBytesAsync();

            bool isHashValid = this.hasher.IsValidHash(data, artifacts.PayloadHash);

            if (!isHashValid)
            {
                Tracing.Information(
                    String.Format("Invalid payload hash {0} for data {1}", artifacts.PayloadHash.ToBase64String(),
                                  Encoding.UTF8.GetString(data)));
            }

            return(isHashValid);
        }
        /// <summary>
        /// Creates the payload hash and the corresponding HMAC, and updates the artifacts object
        /// with these new values.
        /// </summary>
        internal void Sign(string body = null, string contentType = null)
        {
            byte[] responsePayloadHash = null;
            if (body != null && contentType != null)
            {
                var payload = new NormalizedPayload(body, contentType);
                byte[] data = payload.ToBytes();

                Tracing.Verbose("Normalized payload: " + Encoding.UTF8.GetString(data));

                responsePayloadHash = hasher.ComputeHash(data);
            }

            artifacts.PayloadHash = responsePayloadHash;

            byte[] normalizedRequest = this.normalizedRequest.ToBytes();
            artifacts.Mac = hasher.ComputeHmac(normalizedRequest, credential.Key);

            Tracing.Verbose("Normalized request: " + Encoding.UTF8.GetString(normalizedRequest));
        }
Esempio n. 8
0
        /// <summary>
        /// Creates the payload hash and the corresponding HMAC, and updates the artifacts object
        /// with these new values.
        /// </summary>
        internal void Sign(string body = null, string contentType = null)
        {
            byte[] responsePayloadHash = null;
            if (body != null && contentType != null)
            {
                var    payload = new NormalizedPayload(body, contentType);
                byte[] data    = payload.ToBytes();

                Tracing.Verbose("Normalized payload: " + Encoding.UTF8.GetString(data));

                responsePayloadHash = hasher.ComputeHash(data);
            }

            artifacts.PayloadHash = responsePayloadHash;

            byte[] normalizedRequest = this.normalizedRequest.ToBytes();
            artifacts.Mac = hasher.ComputeHmac(normalizedRequest, credential.Key);

            Tracing.Verbose("Normalized request: " + Encoding.UTF8.GetString(normalizedRequest));
        }
Esempio n. 9
0
        /// <summary>
        /// Creates the payload hash and the corresponding HMAC, and updates the artifacts object with these new values.
        /// </summary>
        internal async Task SignAsync(HttpContent newContent)
        {
            byte[] responsePayloadHash = null;
            if (newContent != null)
            {
                var    payload = new NormalizedPayload(newContent);
                byte[] data    = await payload.ToBytesAsync();

                Tracing.Verbose("Normalized payload: " + Encoding.UTF8.GetString(data));

                responsePayloadHash = hasher.ComputeHash(data);
            }

            artifacts.PayloadHash = responsePayloadHash;

            byte[] normalizedRequest = this.normalizedRequest.ToBytes();
            artifacts.Mac = hasher.ComputeHmac(normalizedRequest, credential.Key);

            Tracing.Verbose("Normalized request: " + Encoding.UTF8.GetString(normalizedRequest));
        }
        /// <summary>
        /// Creates the payload hash and the corresponding HMAC, and updates the artifacts object with these new values.
        /// </summary>
        internal async Task SignAsync(HttpContent newContent)
        {
            byte[] responsePayloadHash = null;
            if (newContent != null)
            {
                var payload = new NormalizedPayload(newContent);
                byte[] data = await payload.ToBytesAsync();

                Tracing.Verbose("Normalized payload: " + Encoding.UTF8.GetString(data));

                responsePayloadHash = hasher.ComputeHash(data);
            }

            artifacts.PayloadHash = responsePayloadHash;

            byte[] normalizedRequest = this.normalizedRequest.ToBytes();
            artifacts.Mac = hasher.ComputeHmac(normalizedRequest, credential.Key);

            Tracing.Verbose("Normalized request: " + Encoding.UTF8.GetString(normalizedRequest));
        }