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
(DataFlex) Everyware API RSA Encrypt JSONSee more RSA ExamplesDemonstrates how to RSA encrypt JSON using everyware.com's RSA public key. For more information, see https://docs.everyware.com/docs/access-iframe#sample-json--encrypted-payload
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess Handle hoJson Handle hoDt Handle hoSb Boolean iBCrlf Variant vPubkey Handle hoPubkey Handle hoRsa String sEncryptedJson Handle hoSbUrl String sTemp1 // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // First build the JSON to be encrypted. Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComUpdateString Of hoJson "provider_key" "USER GUID HERE" To iSuccess Get ComUpdateString Of hoJson "menu_item" "payment" To iSuccess Get Create (RefClass(cComCkDateTime)) To hoDt If (Not(IsComObjectCreated(hoDt))) Begin Send CreateComObject of hoDt End Get ComSetFromCurrentSystemTime Of hoDt To iSuccess Get ComGetAsUnixTimeStr Of hoDt False To sTemp1 Get ComUpdateString Of hoJson "date_time" sTemp1 To iSuccess // This build JSON like the following: // { // "provider_key": "USER GUID HERE", // "menu_item": "payment", // "date_time": "1588163411" // } // When we sign, we'll want to sign the most compact JSON possible Set ComEmitCompact Of hoJson To True // Everyware's RSA public key is at: https://docs.everyware.com/docs/everyware-public-rsa-key Get Create (RefClass(cComChilkatStringBuilder)) To hoSb If (Not(IsComObjectCreated(hoSb))) Begin Send CreateComObject of hoSb End Move True To iBCrlf Get ComAppendLine Of hoSb "-----BEGIN PUBLIC KEY-----" iBCrlf To iSuccess Get ComAppendLine Of hoSb "MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxNbflxUSWQ3XJ1N9dAoh" iBCrlf To iSuccess Get ComAppendLine Of hoSb "k+uaiFsg3wkPi9LGS/mH8DtHBgZxKyz+oQBDtnDd9FDEo0ql7MMgCMsTAv27W5vk" iBCrlf To iSuccess Get ComAppendLine Of hoSb "Pu0rm6zhcTeYquWEuVCS7VtVsyTATr0Z9WhqNeZlIRurovJAXl2jRDX6QeY5dayC" iBCrlf To iSuccess Get ComAppendLine Of hoSb "ubwyG4lBWE4fCakGY6zlh+oaElK0rvblqjYoEg3dn4KPRCYGof8OFxLptHThD4cE" iBCrlf To iSuccess Get ComAppendLine Of hoSb "T30j+utVafhO0HRyJ4iR3Pigb4GXdWBtJEEEWddZJizMkjFQkyUAoYLOT8EJ2TW3" iBCrlf To iSuccess Get ComAppendLine Of hoSb "Tz8SvAuHBUEFcPWTSTMAG/bSp5wrYBTXaeEhx+wrYa60OruHuzgmhzKyQVuYlCNJ" iBCrlf To iSuccess Get ComAppendLine Of hoSb "HdbnassuIRjjSNo25o4AdSlWwpGfBZjAiyEInR+KGpHdhKTxSekJxiwiXUS0UfSG" iBCrlf To iSuccess Get ComAppendLine Of hoSb "prOpd5PzWaAR7DvjLsdmR9XffxvJCVxC735gLK7hDJKjCajDPHVDr8FSL8xMlrq0" iBCrlf To iSuccess Get ComAppendLine Of hoSb "nKxtsHeRl1yzoGrRr12+9MiQnHtpqROTNXcXdwe3v+Vh8V5k8v8oIrcgh1+/N7Bd" iBCrlf To iSuccess Get ComAppendLine Of hoSb "NiRsy1gFHBdu/he/KcDRT/9/acQFMPLQueGfZxUvU5As6pEONjtKX2MUg2fMF6Rc" iBCrlf To iSuccess Get ComAppendLine Of hoSb "sQVVrLzg0g7EcuHGfuPeKfD/716MvS8NU7rX+2soijCSQv/e18PJPMVDlcMXjnup" iBCrlf To iSuccess Get ComAppendLine Of hoSb "PPx1tStemesavFlj1okhS6UCAwEAAQ==" iBCrlf To iSuccess Get ComAppendLine Of hoSb "-----END PUBLIC KEY-----" iBCrlf To iSuccess Get Create (RefClass(cComChilkatPublicKey)) To hoPubkey If (Not(IsComObjectCreated(hoPubkey))) Begin Send CreateComObject of hoPubkey End Get ComGetAsString Of hoSb To sTemp1 Get ComLoadFromString Of hoPubkey sTemp1 To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoPubkey To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatRsa)) To hoRsa If (Not(IsComObjectCreated(hoRsa))) Begin Send CreateComObject of hoRsa End Get pvComObject of hoPubkey to vPubkey Get ComImportPublicKeyObj Of hoRsa vPubkey To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoRsa To sTemp1 Showln sTemp1 Procedure_Return End // We probably need a base64Url encoded encrypted key. // Using straight-up base64 would potenially include chars that are not URL safe (i.e. have special meanings in URLs) Set ComEncodingMode Of hoRsa To "base64url" Get ComEmit Of hoJson To sTemp1 Get ComEncryptStringENC Of hoRsa sTemp1 False To sEncryptedJson // Build the URL // Such as: https://portal.everyware.com/Account/LoginMenu?data={Base64Url_encrypted_JSON} Get Create (RefClass(cComChilkatStringBuilder)) To hoSbUrl If (Not(IsComObjectCreated(hoSbUrl))) Begin Send CreateComObject of hoSbUrl End Get ComAppend Of hoSbUrl "https://portal.everyware.com/Account/LoginMenu?data=" To iSuccess Get ComAppend Of hoSbUrl sEncryptedJson To iSuccess Get ComGetAsString Of hoSbUrl To sTemp1 Showln sTemp1 End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.