PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
oleobject loo_Crypt
string ls_PublicKey
string ls_PrivateKey
string ls_Http_verb
string ls_Content_type
string ls_X_bol_date
string ls_Uri
oleobject loo_Sb
string ls_Mac
oleobject loo_SbHeader
string ls_HdrValue
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2")
if li_rc < 0 then
destroy loo_Crypt
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Crypt.EncodingMode = "base64"
loo_Crypt.HashAlgorithm = "sha256"
loo_Crypt.MacAlgorithm = "hmac"
ls_PublicKey = "oRNWbHFXtAECmhnZmEndcjLIaSKbRMVE"
ls_PrivateKey = "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
ls_Http_verb = "GET"
ls_Content_type = "application/xml"
ls_X_bol_date = "Wed, 17 Feb 2016 00:00:00 GMT"
ls_Uri = "/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.
loo_Sb = create oleobject
li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder")
loo_Sb.Append(ls_Http_verb)
loo_Sb.Append("~n~n")
loo_Sb.Append(ls_Content_type)
loo_Sb.Append("~n")
loo_Sb.Append(ls_X_bol_date)
loo_Sb.Append("~nx-bol-date:")
loo_Sb.Append(ls_X_bol_date)
loo_Sb.Append("~n")
loo_Sb.Append(ls_Uri)
Write-Debug "[" + loo_Sb.GetAsString() + "]"
// Set the HMAC key:
loo_Crypt.SetMacKeyEncoded(ls_PrivateKey,"ascii")
ls_Mac = loo_Crypt.MacStringENC(loo_Sb.GetAsString())
// The answer should be: nqzLWvXI1eBhBXrRx5NF23V5hS8Q1xWCloJzPi/RAts=
Write-Debug ls_Mac
// The last step is to append the public key with the signature
loo_SbHeader = create oleobject
li_rc = loo_SbHeader.ConnectToNewObject("Chilkat.StringBuilder")
loo_SbHeader.Append(ls_PublicKey)
loo_SbHeader.Append(":")
loo_SbHeader.Append(ls_Mac)
ls_HdrValue = loo_SbHeader.GetAsString()
Write-Debug ls_HdrValue
destroy loo_Crypt
destroy loo_Sb
destroy loo_SbHeader