Files
  • main.cs
  • main.exe
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Security.Cryptography;
using System.Text;
using System.IO;

class MainClass {
  
  public static void Main (string[] args) {
    // Grades Jounrey Authorization
    // Example of generating a MAC key for     
    // API key and secret are set within the Building Block settings
    string APIKey = "this_is_your_api_key";
    string secret = "no_one_knows_this";
    int validTimeMS = 10000; 

    // Current timestamp in Milliseconds
    string currentTimestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString();
    string timestampExpiry = (DateTime.Now).AddMilliseconds(validTimeMS).ToString();
    string concactString = string.Concat(APIKey, currentTimestamp, secret);

    // Encrypt
    MD5 md5 = new MD5CryptoServiceProvider();
    UTF8Encoding encoder = new UTF8Encoding();
    Byte[] encodedBytes = md5.ComputeHash(encoder.GetBytes(concactString));
    string MAC = BitConverter.ToString(encodedBytes).Replace("-", "").ToLower();
          
    Console.WriteLine("******************************");
    Console.WriteLine("MAC: " + MAC);
    Console.WriteLine ("Valid until: " + timestampExpiry);
    Console.WriteLine("******************************");
  }

}