-
-
Save rorcraft/235823 to your computer and use it in GitHub Desktop.
c# .NET authentication to Ankoder API
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
/* | |
Sample Code for Ankoder API called via .NET C# | |
Written by William Yeung @ Gearbox Software (http://www.gearboxsoft.com) | |
*/ | |
const string PrivateKey = "YOUR_ANKODER_KEY"; | |
var ascii = Encoding.ASCII; | |
var date = DateTime.Now.ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss") + " GMT"; | |
var action_url = "video.xml"; | |
string token=string.Format("-{0}-GET-/{1}-", date, action_url); | |
var salt_binary = SHA1.Create().ComputeHash(ascii.GetBytes(token)); | |
var salt=BitConverter.ToString(salt_binary).Replace("-", "").ToLower().Substring(0,20); | |
HMACSHA1 hmac_sha1 = new HMACSHA1(ascii.GetBytes(PrivateKey)); | |
hmac_sha1.Initialize(); | |
byte[] passkey_binary = hmac_sha1.ComputeHash(ascii.GetBytes(salt)); | |
string passkey = Convert.ToBase64String(passkey_binary).Trim(); | |
WebRequest request = WebRequest.Create(string.Format("http://api.ankoder.com/{0}", action_url)); | |
request.Headers.Add("ankoder_access_key", AccessKey); | |
request.Headers.Add("ankoder_passkey",passkey); | |
request.Headers.Add("ankoder_date", date); | |
request.Method = "GET"; | |
request.GetResponse(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment