Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL oCrypt
LOCAL cPublicKey
LOCAL cPrivateKey
LOCAL cHttp_verb
LOCAL cContent_type
LOCAL cX_bol_date
LOCAL cUri
LOCAL oSb
LOCAL cMac
LOCAL oSbHeader
LOCAL cHdrValue

//  This example assumes the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oCrypt := CreateObject("Chilkat.Crypt2")

oCrypt:EncodingMode := "base64"
oCrypt:HashAlgorithm := "sha256"
oCrypt:MacAlgorithm := "hmac"

cPublicKey := "oRNWbHFXtAECmhnZmEndcjLIaSKbRMVE"
cPrivateKey := "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

cHttp_verb := "GET"
cContent_type := "application/xml"
cX_bol_date := "Wed, 17 Feb 2016 00:00:00 GMT"
cUri := "/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.
oSb := CreateObject("Chilkat.StringBuilder")
oSb:Append(cHttp_verb)
oSb:Append(Chr(10) + Chr(10))
oSb:Append(cContent_type)
oSb:Append(Chr(10))
oSb:Append(cX_bol_date)
oSb:Append(Chr(10) + "x-bol-date:")
oSb:Append(cX_bol_date)
oSb:Append(Chr(10))
oSb:Append(cUri)
? "[" + oSb:GetAsString() + "]"

//  Set the HMAC key:
oCrypt:SetMacKeyEncoded(cPrivateKey, "ascii")
cMac := oCrypt:MacStringENC(oSb:GetAsString())

//  The answer should be: nqzLWvXI1eBhBXrRx5NF23V5hS8Q1xWCloJzPi/RAts=
? cMac

//  The last step is to append the public key with the signature
oSbHeader := CreateObject("Chilkat.StringBuilder")
oSbHeader:Append(cPublicKey)
oSbHeader:Append(":")
oSbHeader:Append(cMac)

cHdrValue := oSbHeader:GetAsString()
? cHdrValue

oCrypt:destroy()
oSb:destroy()
oSbHeader:destroy()