Bitcoin Forum
June 19, 2024, 04:40:50 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: MtGox API login_error_invalid_rest_sign  (Read 598 times)
tulasacra (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
April 27, 2013, 11:27:31 AM
 #1

hello experts Smiley

i am trying to use this project https://bitbucket.org/pipe2grep/cryptocoinxchange/overview (linked from https://en.bitcoin.it/wiki/MtGox/API/HTTP/v2) to access mtGox api.

- commands requiring authentication work (GetAccountInfo etc.)

- commands for trading do not work Sad I am getting the following error "Response contained error: {"result":"error","error":"Identification required to access private API","token":"login_error_invalid_rest_sign"}"
Does anyone here by chance know what the problem might be?

- i have "Trade" checked among the rights for the api key i am using in the mtGox security center

- i have checked the implementation (attached) against the best specification I could find (https://bitbucket.org/nitrous/mtgox-api/overview#markdown-header-security) and seems to be OK

Code:
        protected override RestRequest CCXRestSharpAuthenticate(RestRequest req, object parameters, AccessType accessType)
        {
            if (accessType == AccessType.Public) return req;

            if(TestedApi && !ValidApiKey)
                throw new MissingFieldException("You must configure your API Key");

            Int64 nonce = DateTime.Now.Ticks;

            string endpoint = req.Resource;
            string post = "nonce=" + nonce;
            NameValueCollection nvc = parameters as NameValueCollection;
            if (nvc != null)
            {
                post += ToQueryString(nvc);
                foreach (string s in nvc.Keys)
                {
                    req.AddParameter(s, nvc[s]);
                }
            }
            string prefix = endpoint;

            string sign = getHash(Convert.FromBase64String(APISecret), prefix + Convert.ToChar(0) + post);
            req.AddHeader("Rest-Key", APIKey);
            req.AddHeader("Rest-Sign", sign);
            req.AddParameter("nonce", nonce);
            return req;
        }

        private string getHash(byte[] keyByte, String message)
        {
            var hmacsha512 = new HMACSHA512(keyByte);
            var messageBytes = Encoding.UTF8.GetBytes(message);
            return Convert.ToBase64String(hmacsha512.ComputeHash(messageBytes));
        }

        public string ToQueryString(NameValueCollection parameters)
        {
            if (parameters != null)
            {
                return "&" + string.Join("&", Array.ConvertAll(parameters.AllKeys, key => string.Format("{0}={1}", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(parameters[key]))));
            }

            return "";
        }
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!