Agent Instance ID Generator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nzbot
    Junior Member
    • Feb 2009
    • 14

    #1

    Agent Instance ID Generator

    Hello,

    as you probably already know, web requests to the games API require you to provide an agent ID + agent instance ID. A properly formatted agent ID looks like "myname@company.com.xgamesbot.1.0", the agent instance ID is a MD5 hash like "1b7c01a267d5d5a9e18b1fc856622c60" (see API documentation, page 20ff, http://bdpsupport.betfair.com/ics/su...p?fileID=43981.

    Following C# code can be used to calculate a valid agent instance ID for your agent ID (MD5, as specified in the API documentation). Create a C# console application and replace the auto generated code by this one. Use copy&paste to copy the generated MD5 from the console to your code or configuration file.

    Code:
    using System;
    using System.Security.Cryptography;
    using System.Text;
    
    namespace MD5Generator
    {
        internal class Program
        {
            // Compute MD5 hash code for the given string
            private static string GetMd5Hash(string input) {
                // Create a new instance of the MD5CryptoServiceProvider object
                MD5 md5Hasher = MD5.Create();
    
                // Convert the input string to a byte array and compute the hash
                byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
    
                // Create a new Stringbuilder to collect the bytes and create a string
                StringBuilder builder = new StringBuilder();
    
                // Loop through each byte of the hashed data and format each one as a hexadecimal string
                for (int i = 0; i < data.Length; i++) {
                    builder.Append(data[i].ToString("x2"));
                }
    
                // Return the hexadecimal string
                return builder.ToString();
            }
    
            private static string GetAgentInstanceId(string agentId) {
                Random random = new Random();
                int randomNumber = random.Next(10000, 99999); // must have 5 digits
                StringBuilder builder = new StringBuilder();
                builder.Append(DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss:ff"));
                builder.Append("Z");
                builder.Append(randomNumber);
                builder.Append(agentId);
                return builder.ToString();
            }
    
            private static void Main(string[] args) {
                string agentId = "myname@company.com.xgamesbot.1.0"; // replace this with your own agent ID
                string agentInstanceId = GetAgentInstanceId(agentId);
                Console.WriteLine("Agent ID                 : {0}", agentId);
                Console.WriteLine("Agent Instance ID String : {0}", agentInstanceId);
                Console.WriteLine("Agent Instance ID MD5    : {0}", GetMd5Hash(agentInstanceId));
                Console.ReadLine();
            }
        }
    }
    Hope, this saves you a little bit time
    Best regards!
    Last edited by nzbot; 23-03-2009, 03:32 AM. Reason: [CODE] instead of [FONT][SIZE]
  • elmariachi
    Junior Member
    • Feb 2009
    • 16

    #2
    Nice

    Thx for this. Will save people a huge amount of time.

    Comment

    Working...
    X