Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
themeMidnight
{
    using System;
    using System.Security.Cryptography;
    using System.Text;
 
    public static class AuthHeaderHelper
 
  {
  
     /// <summary>
        /// The following function creats the needed authentication header to work for ApiToken
        /// HttpRequestMessage.Headers.Authorization = new AuthenticationHeaderValue("ARMOR-PSK", authValue)
        /// </summary>
        /// <param name="apiKey">use>Unique Id thecreated apiby keythe id<customer</param>
 
      /// <param name="secretKey">use>The the secret key</param>key generated by       /// <param name="nonce">A unique value, has 5 min lifespan</param>the customer.</param>      
    /// <param name="requestPath">absolute path: Example: /accounts/2</param>
        /// <param name="requestBody">Request body applies.</param>
        /// <param name="timestamp">Must be current time</param>
        /// <param name="httpMethod">Http Method: GET, POST, ...</param>
  
     /// <returns>string auth header Example: 'ARMOR-PSK apiKey:signature:nonce:unixTime'</returns>
        public static string CreateAuthorizationHeader(string apiKey, string secretKey, string nonce, string requestPath, string requestBody, DateTime? timestamp, string httpMethod = "GET")
        {
            var dateTimerequestContentBase64String = timestamp ?? DateTime.UtcNowstring.Empty;
              using (var sha512 = new SHA512Managed())
            {
                var requestBodyBytes = Encoding.ASCII.GetBytes(requestBody);
    AUTH_TYPE = "ARMOR-PSK";
           var contenttimestamp = ConvertDateTimeOffset.ToBase64String(sha512.ComputeHash(requestBodyBytes));
                requestBody = content.Length != 0 ? content : string.Empty;
            }
 
            Console.WriteLine("Request Body is: {0}", requestBody);
            requestPath = "/accounts/2".ToLowerUtcNow.ToUnixTimeSeconds();
              var unixTimenonce = (Int32)(dateTime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
  timestamp;
         var requestData = string.Format("{0}{1}{2}{3}{4}{5}", apiKey, httpMethod, requestPath, unixTime, nonce, requestBody);
            Console.WriteLine("Request Data is: {0}", requestData)apiKey + httpMethod + requestPath + nonce + timestamp + requestBody;
            string signature = string.Emptybyte[] mac;
            using (var hmac = new HMACSHA512(Encoding.UTF8.GetBytes(secretKey)))
  
         {
                var resultmac = hmac.ComputeHash(Encoding.UTF8.GetBytes(requestData));
        }
        var signature = Convert.ToBase64String(resultmac);
        var authHeader = AUTH_TYPE }+ ' ' + apiKey + ':' + signature + ':' + nonce   return string.Format("{0}:{1}:{2}:{3}", apiKey, signature, nonce, unixTime);+ ':' + timestamp;
        return }authHeader;
    }
}


Step 3: Make an API Call

...