Skip to main content

Set authentication


Each API request requires setting the following headers:

HeaderDescription
X-Api-KeyThe SHA256 hash from your public API key in Base64 format.
X-Api-SignatureThe query's serialized body. You must sign it with your private key according to the RSA-SHA256 method.

Code samples

The following code samples illustrate how to authenticate and send signed requests.

info

Recommend .NET version is 10.0.

using System.Net.Http;
using System.Security.Cryptography;
using System.Text.Json;

const string PRIVATE_KEY_HEX = "YOUR_PRIVATE_KEY";

byte[] pkcs8Bytes = Convert.FromHexString(PRIVATE_KEY_HEX);

using RSA rsa = RSA.Create();
rsa.ImportPkcs8PrivateKey(pkcs8Bytes, out _);

byte[] pkcs1Der = rsa.ExportRSAPublicKey();

byte[] publicKeyHash = SHA256.HashData(pkcs1Der);
string xApiKey = Convert.ToBase64String(publicKeyHash);

var message = new { jsonrpc = "2.0", id = "test", method = "getCurrencies" };
byte[] body = JsonSerializer.SerializeToUtf8Bytes(message);

byte[] signatureBytes = rsa.SignData(body, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
string xApiSignature = Convert.ToBase64String(signatureBytes);

using HttpClientHandler handler = new()
{
ServerCertificateCustomValidationCallback =
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator,
};
using HttpClient client = new(handler);

using HttpRequestMessage request = new(HttpMethod.Post, "https://api.criptointercambio.com/v2/")
{
Content = new ByteArrayContent(body),
};
request.Content.Headers.ContentType =
new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
request.Headers.Add("X-Api-Key", xApiKey);
request.Headers.Add("X-Api-Signature", xApiSignature);

HttpResponseMessage response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());