protected override async Task ProcessRequestAsync(HttpWebRequest request, Dictionary <string, object> payload) { if (CanMakeAuthenticatedRequest(payload)) { // gdax is funny and wants a seconds double for the nonce, weird... we convert it to double and back to string invariantly to ensure decimal dot is used and not comma string timestamp = payload["nonce"].ToStringInvariant(); payload.Remove("nonce"); string form = CryptoUtility.GetJsonForPayload(payload); byte[] secret = CryptoUtility.ToBytesBase64Decode(PrivateApiKey); string toHash = timestamp + request.Method.ToUpper() + request.RequestUri.PathAndQuery + form; string signatureBase64String = CryptoUtility.SHA256SignBase64(toHash, secret); secret = null; toHash = null; request.Headers["CB-ACCESS-KEY"] = PublicApiKey.ToUnsecureString(); request.Headers["CB-ACCESS-SIGN"] = signatureBase64String; request.Headers["CB-ACCESS-TIMESTAMP"] = timestamp; request.Headers["CB-ACCESS-PASSPHRASE"] = CryptoUtility.ToUnsecureString(Passphrase); await CryptoUtility.WriteToRequestAsync(request, form); } }
protected override async Task ProcessRequestAsync(HttpWebRequest request, Dictionary <string, object> payload) { if (CanMakeAuthenticatedRequest(payload)) { payload.Remove("nonce"); string body = CryptoUtility.GetJsonForPayload(payload); string timestamp = ((int)DateTime.UtcNow.UnixTimestampFromDateTimeSeconds()).ToStringInvariant(); string msg = timestamp + request.Method + request.RequestUri.PathAndQuery + (request.Method.Equals("POST") ? body : string.Empty); string sign = CryptoUtility.SHA256SignBase64(msg, CryptoUtility.ToBytesBase64Decode(PrivateApiKey)); request.Headers["AC-ACCESS-KEY"] = CryptoUtility.ToUnsecureString(PublicApiKey); request.Headers["AC-ACCESS-SIGN"] = sign; request.Headers["AC-ACCESS-TIMESTAMP"] = timestamp; request.Headers["AC-ACCESS-PASSPHRASE"] = CryptoUtility.ToUnsecureString(Passphrase); if (request.Method == "POST") { await CryptoUtility.WriteToRequestAsync(request, body); } } }