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
(PowerBuilder) Plaza API (bol.com) HMAC-SHA256 AuthenticationDemonstrates how to compute the Authorization header for bol.com using HMAC-SHA256.
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 // Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0 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 // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 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 // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 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 |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.