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) ClickBank Decrypt Instant NotificationDemonstrates how to decrypt a ClickBank instant notification. See Instant Notification Service for more information and alternative code snippets.
IncludeFile "CkBinData.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkCrypt2.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. ; secret key from your ClickBank account secretKey.s = "MY_SECRET_KEY" jsonStr.s = "{" + Chr(34) + "notification" + Chr(34) + ":" + Chr(34) + "BASE64_NOTIFICATION" + Chr(34) + "," + Chr(34) + "iv" + Chr(34) + ":" + Chr(34) + "BASE64_IV" + Chr(34) + "}" json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkJsonObject::ckLoad(json,jsonStr) ; Get the encrypted notification (binary) and IV from the JSON. bdNotif.i = CkBinData::ckCreate() If bdNotif.i = 0 Debug "Failed to create object." ProcedureReturn EndIf bdIv.i = CkBinData::ckCreate() If bdIv.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkBinData::ckAppendEncoded(bdNotif,CkJsonObject::ckStringOf(json,"notification"),"base64") success = CkBinData::ckAppendEncoded(bdIv,CkJsonObject::ckStringOf(json,"iv"),"base64") ; Get an SHA1 digest (as a hex string) of the secret key. ; A SHA1 digest is 20 bytes. Therefore the hex string is 40 chars. ; Treat each us-ascii char as a binary byte of the secret key. ; 256-bit AES needs a 256-bit key, which is 32-bytes. Therefore ; use the 1st 32 us-ascii chars of the hex SHA1 as the AES secret key. crypt.i = CkCrypt2::ckCreate() If crypt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Because we're using the hex string as the actual AES key, it matters whether the hex is uppercase or lowercase. ; We want lowercase. CkCrypt2::setCkEncodingMode(crypt, "hex_lower") CkCrypt2::setCkHashAlgorithm(crypt, "sha1") hexSha1.s = CkCrypt2::ckHashStringENC(crypt,secretKey) Debug hexSha1 ; Treat the hex string as binary data for the AES key.. bdKey.i = CkBinData::ckCreate() If bdKey.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkBinData::ckAppendString(bdKey,hexSha1,"us-ascii") CkBinData::ckRemoveChunk(bdKey,32,8) CkCrypt2::setCkKeyLength(crypt, 256) CkCrypt2::setCkCryptAlgorithm(crypt, "aes") CkCrypt2::setCkCipherMode(crypt, "cbc") ; We can use any encoding because were just getting the binary bytes in an encoding, and then setting from the same encoding. ; We'll just use base64.. CkCrypt2::ckSetEncodedIV(crypt,CkBinData::ckGetEncoded(bdIv,"base64"),"base64") CkCrypt2::ckSetEncodedKey(crypt,CkBinData::ckGetEncoded(bdKey,"base64"),"base64") CkCrypt2::ckDecryptBd(crypt,bdNotif) Debug "Decrypted: " + CkBinData::ckGetString(bdNotif,"utf-8") CkJsonObject::ckDispose(json) CkBinData::ckDispose(bdNotif) CkBinData::ckDispose(bdIv) CkCrypt2::ckDispose(crypt) CkBinData::ckDispose(bdKey) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.