private Dictionary <string, string> BuildHeaders(string contentType, string requestPayload, string canonicalQueryString)
        {
            string endpoint = this.Endpoint;

            if (!string.IsNullOrEmpty(this.Profile.HttpProfile.Endpoint))
            {
                endpoint = this.Profile.HttpProfile.Endpoint;
            }
            string httpRequestMethod    = this.Profile.HttpProfile.ReqMethod;
            string canonicalURI         = "/";
            string canonicalHeaders     = "content-type:" + contentType + "; charset=utf-8\nhost:" + endpoint + "\n";
            string signedHeaders        = "content-type;host";
            string hashedRequestPayload = SignHelper.SHA256Hex(requestPayload);
            string canonicalRequest     = httpRequestMethod + "\n"
                                          + canonicalURI + "\n"
                                          + canonicalQueryString + "\n"
                                          + canonicalHeaders + "\n"
                                          + signedHeaders + "\n"
                                          + hashedRequestPayload;

            string algorithm              = "TC3-HMAC-SHA256";
            long   timestamp              = ToTimestamp() / 1000;
            string requestTimestamp       = timestamp.ToString();
            string date                   = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(timestamp).ToString("yyyy-MM-dd");
            string service                = endpoint.Split('.')[0];
            string credentialScope        = date + "/" + service + "/" + "tc3_request";
            string hashedCanonicalRequest = SignHelper.SHA256Hex(canonicalRequest);
            string stringToSign           = algorithm + "\n"
                                            + requestTimestamp + "\n"
                                            + credentialScope + "\n"
                                            + hashedCanonicalRequest;

            byte[] tc3SecretKey   = Encoding.UTF8.GetBytes("TC3" + Credential.SecretKey);
            byte[] secretDate     = SignHelper.HmacSHA256(tc3SecretKey, Encoding.UTF8.GetBytes(date));
            byte[] secretService  = SignHelper.HmacSHA256(secretDate, Encoding.UTF8.GetBytes(service));
            byte[] secretSigning  = SignHelper.HmacSHA256(secretService, Encoding.UTF8.GetBytes("tc3_request"));
            byte[] signatureBytes = SignHelper.HmacSHA256(secretSigning, Encoding.UTF8.GetBytes(stringToSign));
            string signature      = BitConverter.ToString(signatureBytes).Replace("-", "").ToLower();

            string authorization = algorithm + " "
                                   + "Credential=" + Credential.SecretId + "/" + credentialScope + ", "
                                   + "SignedHeaders=" + signedHeaders + ", "
                                   + "Signature=" + signature;

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Authorization", authorization);
            headers.Add("Host", endpoint);
            headers.Add("Content-Type", contentType);
            headers.Add("X-TC-Timestamp", requestTimestamp);
            headers.Add("X-TC-Version", this.ApiVersion);
            headers.Add("X-TC-Region", this.Region);
            headers.Add("X-TC-RequestClient", this.SdkVersion);
            if (!string.IsNullOrEmpty(this.Credential.Token))
            {
                headers.Add("X-TC-Token", this.Credential.Token);
            }
            return(headers);
        }
        private Dictionary <string, string> FormatRequestData(string action, Dictionary <string, string> param)
        {
            param.Add("Action", action);
            param.Add("RequestClient", this.SdkVersion);
            param.Add("Nonce", Math.Abs(new Random().Next()).ToString());

            long unixTime = ToTimestamp();

            param.Add("Timestamp", (unixTime / 1000).ToString());
            param.Add("Version", this.ApiVersion);

            if (!string.IsNullOrEmpty(this.Credential.SecretId))
            {
                param.Add("SecretId", this.Credential.SecretId);
            }

            if (!string.IsNullOrEmpty(this.Region))
            {
                param.Add("Region", this.Region);
            }

            if (!string.IsNullOrEmpty(this.Profile.SignMethod))
            {
                param.Add("SignatureMethod", this.Profile.SignMethod);
            }

            if (!string.IsNullOrEmpty(this.Credential.Token))
            {
                param.Add("Token", this.Credential.Token);
            }

            string endpoint = this.Endpoint;

            if (!string.IsNullOrEmpty(this.Profile.HttpProfile.Endpoint))
            {
                endpoint = this.Profile.HttpProfile.Endpoint;
            }

            string sigInParam = SignHelper.MakeSignPlainText(new SortedDictionary <string, string>(param, StringComparer.Ordinal),
                                                             this.Profile.HttpProfile.ReqMethod, endpoint, this.Path);
            string sigOutParam = SignHelper.Sign(this.Credential.SecretKey, sigInParam, this.Profile.SignMethod);

            param.Add("Signature", sigOutParam);
            return(param);
        }