Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Plaza API (bol.com) HMAC-SHA256 AuthenticationDemonstrates how to compute the Authorization header for bol.com using HMAC-SHA256.
IncludeFile "CkCrypt2.pb" IncludeFile "CkStringBuilder.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. crypt.i = CkCrypt2::ckCreate() If crypt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkCrypt2::setCkEncodingMode(crypt, "base64") CkCrypt2::setCkHashAlgorithm(crypt, "sha256") CkCrypt2::setCkMacAlgorithm(crypt, "hmac") publicKey.s = "oRNWbHFXtAECmhnZmEndcjLIaSKbRMVE" privateKey.s = "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 http_verb.s = "GET" content_type.s = "application/xml" x_bol_date.s = "Wed, 17 Feb 2016 00:00:00 GMT" uri.s = "/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. sb.i = CkStringBuilder::ckCreate() If sb.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sb,http_verb) CkStringBuilder::ckAppend(sb,Chr(10) + Chr(10)) CkStringBuilder::ckAppend(sb,content_type) CkStringBuilder::ckAppend(sb,Chr(10)) CkStringBuilder::ckAppend(sb,x_bol_date) CkStringBuilder::ckAppend(sb,Chr(10) + "x-bol-date:") CkStringBuilder::ckAppend(sb,x_bol_date) CkStringBuilder::ckAppend(sb,Chr(10)) CkStringBuilder::ckAppend(sb,uri) Debug "[" + CkStringBuilder::ckGetAsString(sb) + "]" ; Set the HMAC key: CkCrypt2::ckSetMacKeyEncoded(crypt,privateKey,"ascii") mac.s = CkCrypt2::ckMacStringENC(crypt,CkStringBuilder::ckGetAsString(sb)) ; The answer should be: nqzLWvXI1eBhBXrRx5NF23V5hS8Q1xWCloJzPi/RAts= Debug mac ; The last step is to append the public key with the signature sbHeader.i = CkStringBuilder::ckCreate() If sbHeader.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbHeader,publicKey) CkStringBuilder::ckAppend(sbHeader,":") CkStringBuilder::ckAppend(sbHeader,mac) hdrValue.s = CkStringBuilder::ckGetAsString(sbHeader) Debug hdrValue CkCrypt2::ckDispose(crypt) CkStringBuilder::ckDispose(sb) CkStringBuilder::ckDispose(sbHeader) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.