Versions Compared

Key

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

You can use the API tokenization (C#) feature in the Armor Management Portal (AMP) to create an API key. This key will help you log into the Armor API system.  


Step 1: Create an API key

ESLP:Create an API (snippet)

Insert excerpt
ESLP:Create an API (snippet)
Pre-Shared Key Authentication Method
Pre-Shared Key Authentication Method
nameCreate API Key
nopaneltrue


Step 2: Authenticate into the Armor API system

To authenticate, you need to build a header with the following components:  

Parameter

Description

apiKey

Enter the Key ID generated from AMP.

Note

In the example below, replace use the api key id with your key ID.

secretKey

Enter the Secret Key generated from AMP.

Note

In the example below, replace use the secret key with your secret key.

nonce

Enter a unique ID.

  • This ID should be unique per request.

  • This ID cannot be longer than 128 characters.

  • This ID cannot contain a colon ( : ).

 

requestPath


requestBody


timestamp

Enter a Unix time stamp within 5 minutes of the current time.

httpMethod

Enter GET or POST.

Info

For all v2 API's, the request body should be empty.

Code Block
languagejsthemeMidnight
{
    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.UtcNow;
 
    string.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);
    UtcNow.ToUnixTimeSeconds();
       requestPath = "/accounts/2".ToLower();
 
            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.Empty;
  byte[] mac;
         using (var hmac = new HMACSHA512(Encoding.UTF8.GetBytes(secretKey)))
   
        {
                var result mac = 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

To learn about the different calls that you can make, see see Armor API Guide.

Related Documentation Documentation

...