Created
April 1, 2014 14:41
-
-
Save anonymous/9915500 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class GenerateHash | |
{ | |
private string key; | |
private string secret; | |
public GenerateHash(string key, string secret) | |
{ | |
this.key = key; | |
this.secret = secret; | |
} | |
public int GetEpoch() | |
{ | |
return (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; | |
} | |
public string GetAuthorizationHeader() | |
{ | |
string epoch = GetEpoch().ToString(); | |
string stringTosign = string.Concat(key, epoch); | |
byte[] secretBytes = Encoding.ASCII.GetBytes(secret); | |
using (HMACSHA256 myhmacsha1 = new HMACSHA256(secretBytes)) | |
{ | |
byte[] byteArray = Encoding.ASCII.GetBytes(stringTosign); | |
byte[] hashValue = myhmacsha1.ComputeHash(byteArray); | |
string hashToBase64 = Convert.ToBase64String(hashValue); | |
string keyHashEpoch = string.Format("{0}:{1}:{2}", key, hashToBase64, epoch); | |
byte[] keyHashEpochBytes = Encoding.ASCII.GetBytes(keyHashEpoch); | |
string s = Convert.ToBase64String(keyHashEpochBytes); //BitConverter.ToString(keyHashEpochBytes); | |
return string.Concat("A5-API ", s); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment