using System.Security.Cryptography;
public static void Main()
string uri = string.Format("/api/carrier/order/{0}/status", 100000429);
string url = string.Format("https://delfin2.getprintbox.com{0}",uri);
string json = string.Format("{{\"statusId\":{0}}}", orderStatus);
string apiKey = "a3d4bacb-755e-4d0f-be39-da7e68f5e80c";
string apiSecret = "eeyE6bHF0aFvwX3RHg4Au2abJBMA7F6W";
string time = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:sszzz");
string elHash = sha256(json);
string text = string.Format("{0}\ntime:{1}\nrequestUri:{2}\n{3}", "POST",time, uri ,elHash);
var aux = hmacSHA256(text, apiSecret);
string signature = System.Convert.ToBase64String(aux);
var http = (HttpWebRequest)WebRequest.Create(url);
http.Accept = "application/json";
http.ContentType = "application/json";
using (var streamWriter = new StreamWriter(http.GetRequestStream()))
streamWriter.Write(json);
http.Headers.Add("Time", time);
http.Headers.Add("Authorization", String.Format("Signature ApiKey=\"{0}\", Signature=\"{1}\"", apiKey, signature));
var response = (HttpWebResponse)http.GetResponse();
using (var streamReader = new StreamReader(response.GetResponseStream()))
var result = streamReader.ReadToEnd();
Console.WriteLine(result);
public static string sha256(string text)
using (SHA256 sha256Hash = SHA256.Create())
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(text));
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
builder.Append(bytes[i].ToString("x2"));
return builder.ToString();
public static byte[] hmacSHA256(string text, string apiKey)
var encoding = new ASCIIEncoding();
byte[] textByte = encoding.GetBytes(text);
byte[] apiKeyByte = encoding.GetBytes(apiKey);
var hash = new HMACSHA256(apiKeyByte);
return hash.ComputeHash(textByte);