Ejemplo n.º 1
0
        protected string GenerateSignature(string appId, string path, string method, string nonce, string timestamp, string authorizationKey)
        {
            var value = string.Format("{0}{1}{2}{3}{4}",
                                      appId, path, method, nonce, timestamp);

            return(HMACSHA256.Hash(value, authorizationKey));
        }
Ejemplo n.º 2
0
        public static string GenerateAuthorizationHeader(ElencyConfiguration config, string path, string method, bool hmac = false)
        {
            var dateTime1970 = new DateTime(1970, 1, 1);
            var span         = DateTime.UtcNow - dateTime1970;
            var timestamp    = span.TotalMilliseconds.ToString("0");
            var nonce        = Guid.NewGuid().ToString();
            var value        = string.Format("{0}{1}{2}{3}{4}",
                                             config.AppId,
                                             path.ToLower(),
                                             method.ToLower(),
                                             nonce,
                                             timestamp);
            var key       = (hmac == true ? config.HMACAuthorizationKey : config.ConfigEncryptionKey);
            var signature = HMACSHA256.Hash(value, key);

            return(string.Format("{0}:{1}:{2}:{3}",
                                 config.AppId,
                                 signature,
                                 nonce,
                                 timestamp));
        }
Ejemplo n.º 3
0
        public void Hash()
        {
            var hash = HMACSHA256.Hash("TheValueToEncrypt", "aGVsbG93b3JsZA==");

            Assert.AreEqual(hash, "j8l2ru3YrVfmCsfF51eIDw4RZ9gCh9Mm0KbSm5JfeJ0=");
        }