protected override async Task ProcessRequestAsync(HttpWebRequest request, Dictionary <string, object> payload) { if (payload == null || PrivateApiKey == null || PublicApiKey == null || !payload.ContainsKey("nonce")) { await CryptoUtility.WritePayloadFormToRequestAsync(request, payload); } else { string nonce = payload["nonce"].ToStringInvariant(); payload.Remove("nonce"); string form = CryptoUtility.GetFormForPayload(payload); // nonce must be first on Kraken form = "nonce=" + nonce + (string.IsNullOrWhiteSpace(form) ? string.Empty : "&" + form); using (SHA256 sha256 = SHA256Managed.Create()) { string hashString = nonce + form; byte[] sha256Bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(hashString)); byte[] pathBytes = Encoding.UTF8.GetBytes(request.RequestUri.AbsolutePath); byte[] sigBytes = new byte[sha256Bytes.Length + pathBytes.Length]; pathBytes.CopyTo(sigBytes, 0); sha256Bytes.CopyTo(sigBytes, pathBytes.Length); byte[] privateKey = System.Convert.FromBase64String(CryptoUtility.ToUnsecureString(PrivateApiKey)); using (System.Security.Cryptography.HMACSHA512 hmac = new System.Security.Cryptography.HMACSHA512(privateKey)) { string sign = System.Convert.ToBase64String(hmac.ComputeHash(sigBytes)); request.Headers.Add("API-Sign", sign); } } request.Headers.Add("API-Key", CryptoUtility.ToUnsecureString(PublicApiKey)); await CryptoUtility.WriteToRequestAsync(request, form); } }
protected override async Task ProcessRequestAsync(HttpWebRequest request, Dictionary <string, object> payload) { if (CanMakeAuthenticatedRequest(payload)) { if (string.IsNullOrWhiteSpace(CustomerId)) { throw new APIException("Customer ID is not set for Bitstamp"); } // messageToSign = nonce + customer_id + api_key string apiKey = PublicApiKey.ToUnsecureString(); string messageToSign = payload["nonce"].ToStringInvariant() + CustomerId + apiKey; string signature = CryptoUtility.SHA256Sign(messageToSign, PrivateApiKey.ToUnsecureString()).ToUpperInvariant(); payload["signature"] = signature; payload["key"] = apiKey; await CryptoUtility.WritePayloadFormToRequestAsync(request, payload); } }