Unicode C++
Unicode C++
Plaza API (bol.com) HMAC-SHA256 Authentication
See more Encryption Examples
Demonstrates how to compute the Authorization header for bol.com using HMAC-SHA256.Chilkat Unicode C++ Downloads
#include <CkCrypt2W.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkCrypt2W crypt;
crypt.put_EncodingMode(L"base64");
crypt.put_HashAlgorithm(L"sha256");
crypt.put_MacAlgorithm(L"hmac");
const wchar_t *publicKey = L"oRNWbHFXtAECmhnZmEndcjLIaSKbRMVE";
const wchar_t *privateKey = L"MaQHPOnmYkPZNgeRziPnQyyOJYytUbcFBVJBvbMKoDdpPqaZbaOiLUTWzPAkpPsZFZbJHrcoltdgpZolyNcgvvBaKcmkqFjucFzXhDONTsPAtHHyccQlLUZpkOuywMiOycDWcCySFsgpDiyGnCWCZJkNTtVdPxbSUTWVIFQiUxaPDYDXRQAVVTbSVZArAZkaLDLOoOvPzxSdhnkkJWzlQDkqsXNKfAIgAldrmyfROSyCGMCfvzdQdUQEaYZTPEoA";
// The string to sign is this:
// http_verb +'\n\n'+ content_type +'\n'+ x_bol_date +'\n'+ 'x-bol-date:'+ x_bol_date +'\n'+ uri
const wchar_t *http_verb = L"GET";
const wchar_t *content_type = L"application/xml";
const wchar_t *x_bol_date = L"Wed, 17 Feb 2016 00:00:00 GMT";
const wchar_t *uri = L"/services/rest/orders/v2";
// IMPORTANT: Notice the use of underscore and hyphen (dash) chars in x-bol-date vs. x_bol_date.
// In one place hypens are used. In two places, underscore chars are used.
CkStringBuilderW sb;
sb.Append(http_verb);
sb.Append(L"\n\n");
sb.Append(content_type);
sb.Append(L"\n");
sb.Append(x_bol_date);
sb.Append(L"\nx-bol-date:");
sb.Append(x_bol_date);
sb.Append(L"\n");
sb.Append(uri);
wprintf(L"[%s]\n",sb.getAsString());
// Set the HMAC key:
crypt.SetMacKeyEncoded(privateKey,L"ascii");
const wchar_t *mac = crypt.macStringENC(sb.getAsString());
// The answer should be: nqzLWvXI1eBhBXrRx5NF23V5hS8Q1xWCloJzPi/RAts=
wprintf(L"%s\n",mac);
// The last step is to append the public key with the signature
CkStringBuilderW sbHeader;
sbHeader.Append(publicKey);
sbHeader.Append(L":");
sbHeader.Append(mac);
const wchar_t *hdrValue = sbHeader.getAsString();
wprintf(L"%s\n",hdrValue);
}