I am playing around implementing an API. Usually that is really simple, but this one gives me problems. However, I am pretty sure the problem is me, and not the API.
Url to this specific API:
I want to make POST call to the "Account balance". Currently I get the following answer:
{"error": "Missing key, signature and nonce parameters"}
and I try to do it with the following code:
        var path = "https://www.bitstamp.net/api/user_transactions";
        var nonce = GetNonce();
        var signature = GetSignature(nonce);
        using (WebClient client = new WebClient())
        {
            byte[] response = client.UploadValues(path, new NameValueCollection()
           {
               { "key", Constants.ThirdParty.BitStamp.ApiKey },
               { "signature", signature },
               { "nonce", nonce},
           });
            var str = System.Text.Encoding.Default.GetString(response);
        }
        return 0.0m;
This is my two helper functions:
    private string GetSignature(int nonce)
    {
        string msg = string.Format("{0}{1}{2}", nonce,
            Constants.ThirdParty.BitStamp.ClientId,
            Constants.ThirdParty.BitStamp.ApiKey);
        return HelperFunctions.sign(Constants.ThirdParty.BitStamp.ApiSecret, msg);
    }
    public static int GetNonce()
    {
        return (int) (DateTime.Now - new DateTime(1970, 1, 1)).TotalSeconds;
    }
My crypto sign function is this one:
    public static String sign(String key, String stringToSign)
    {
        System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
        byte[] keyByte = encoding.GetBytes(key);
        HMACSHA256 hmacsha256 = new HMACSHA256(keyByte);
        return Convert.ToBase64String(hmacsha256.ComputeHash(encoding.GetBytes(stringToSign)));
    }
Any idea why i get the "missing key" error? Is there something obvious I am doing wrong (probably is :) )?
Edit:
Fiddler tells me I post the following data:
key=mykeymykey&signature=PwhdkSek6GP%2br%2bdd%2bS5aU1MryXgrfOD4fLH05D7%2fRLQ%3d&nonce=1382299103%2c21055
Edit #2:
Updated code on generating the signature:
private string GetSignature(int nonce)
    {
        string msg = string.Format("{0}{1}{2}", nonce,
            Constants.ThirdParty.BitStamp.ClientId,
            Constants.ThirdParty.BitStamp.ApiKey);
        return HelperFunctions.ByteArrayToString(HelperFunctions.SignHMACSHA256(
            Constants.ThirdParty.BitStamp.ApiSecret, msg)).ToUpper();
    }
public static byte[] SignHMACSHA256(String key, byte[] data)
{
    HMACSHA256 hashMaker = new HMACSHA256(Encoding.ASCII.GetBytes(key));
    return hashMaker.ComputeHash(data);
}
public static byte[] StrinToByteArray(string str)
{
    byte[] bytes = new byte[str.Length * sizeof(char)];
    System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
    return bytes;
}
public static string ByteArrayToString(byte[] ba)
{
    return BitConverter.ToString(ba).Replace("-", "");
}
 
     
    