[Beginner]help me with sending signed api requests with ApiKey and ApiSecret.

so far i have learned to send http requests to public api and get the respond and deserilize and use the result. but now i am stuck at sending signed requests with ApiSecret.
here is my code so far:

 HMACSHA512 hashMaker; const string BaseUrl = "http://ift.tt/1HTbB6a;; const string ApiKey = "ApiKeyGoesHere"; const string ApiSecret = "ApiSecretGoesHere"; private async Task<string> SendApiRequestAsync() { using (HttpClient client = new HttpClient()) { string url = BaseUrl + "account/getbalance?apikey=" + ApiKey; string myParams = "&currency=" + "DOGE"; client.BaseAddress = new Uri(url); client.DefaultRequestHeaders.Add("apisign",genHMAC(myParams)); Task<string> respond = client.GetStringAsync(url); return await respond; } } private string genHMAC(string url) { var hmac = new HMACSHA512(Encoding.ASCII.GetBytes(ApiSecret)); var messagebyte = Encoding.ASCII.GetBytes(url); var hashmessage = hmac.ComputeHash(messagebyte); var sign = BitConverter.ToString(hashmessage).Replace("-", ""); return sign; } 

this returns an "Invalid Currency" error.
here is the API documentation with a PHP example http://ift.tt/1otLk7Z
i can't quite figure out what should the request look like. i mean should i sign the whole url or just the parameters part.

by pooya87 via /r/csharp

Leave a Reply