Created
September 16, 2013 18:52
-
-
Save joelmgallant/6584854 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// API level authentication field | |
// [JsonProperty("api_auth_token")] | |
public string GetApiAuthToken(string jsonRequest) | |
{ | |
/* API Level authentication requires an additional ‘api_auth_token’ key/value added to the POST message. | |
* This token is generated calculating the MD5 sum of the concatenation of the value sent in apirequest, | |
* the literal string ‘:’ and the api_key */ | |
string api_key = "007ea564129df0fd72eca0df9228245d324c301dddc9254b35a0cd93c4101718"; | |
string hashedValue = ""; | |
Debug.Log("Generating API hash for : " + jsonRequest); | |
// quicker way: | |
/*string strInput = jsonRequest + ":" + api_key; | |
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(strInput); | |
return System.BitConverter.ToString(new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(inputBytes)).Replace("-", "").ToLower(); | |
*/ | |
// VVV longer way.... | |
// create the hash object & poulate it with the bytes of the input string. | |
System.Security.Cryptography.MD5 md5Hash = new System.Security.Cryptography.MD5CryptoServiceProvider(); | |
byte[] hashRequest = System.Text.Encoding.ASCII.GetBytes(jsonRequest + ":" + api_key); | |
// do the hashing... | |
byte[] hashResult = md5Hash.ComputeHash(hashRequest); | |
// convert back to a string (x2 for lowercase) | |
System.Text.StringBuilder result = new System.Text.StringBuilder(hashResult.Length * 2); | |
for(int i = 0; i < hashResult.Length; i++) | |
{ | |
result.Append(hashResult[i].ToString("x2")); | |
} | |
hashedValue = result.ToString(); | |
return hashedValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment