Exemplo n.º 1
0
        /// <summary>
        /// SignRequest
        /// </summary>
        /// <param name="request"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string SignRequest(System.Net.HttpWebRequest request, byte[] body)
        {
            Uri u = request.RequestUri;

            var algorithm            = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithm.HmacSha1);
            CryptographicHash hasher = algorithm.CreateHash(secretKey);

            hasher.Append(body);
            byte[] mac       = hasher.GetValueAndReset();
            string macBase64 = Convert.ToBase64String(mac);

            string pathAndQuery = request.RequestUri.PathAndQuery;

            byte[] pathAndQueryBytes = Config.Encoding.GetBytes(pathAndQuery);
            using (MemoryStream buffer = new MemoryStream())
            {
                buffer.Write(pathAndQueryBytes, 0, pathAndQueryBytes.Length);
                buffer.WriteByte((byte)'\n');
                if (body.Length > 0)
                {
                    buffer.Write(body, 0, body.Length);
                }
                hasher.Dispose();
                return(this.accessKey + ":" + macBase64);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Implements the Dispose pattern
 /// </summary>
 /// <param name="disposing">Whether this object is being disposed via a call to Dispose
 /// or garbage collected.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing && _hash != null)
     {
         _hash.Dispose();
         _hash = null;
     }
 }