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

            return this.hasher.IsValidHash(data, artifacts.PayloadHash);
        }
        /// <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. 4
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);
        }
Esempio n. 5
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));
        }