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) 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
integer li_rc integer li_Success oleobject loo_Json oleobject loo_Dt oleobject loo_Sb integer li_BCrlf oleobject loo_Pubkey oleobject loo_Rsa string ls_EncryptedJson oleobject loo_SbUrl // 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. loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") if li_rc < 0 then destroy loo_Json MessageBox("Error","Connecting to COM object failed") return end if loo_Json.UpdateString("provider_key","USER GUID HERE") loo_Json.UpdateString("menu_item","payment") loo_Dt = create oleobject // Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0 li_rc = loo_Dt.ConnectToNewObject("Chilkat.CkDateTime") loo_Dt.SetFromCurrentSystemTime() loo_Json.UpdateString("date_time",loo_Dt.GetAsUnixTimeStr(0)) // 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 loo_Json.EmitCompact = 1 // Everyware's RSA public key is at: https://docs.everyware.com/docs/everyware-public-rsa-key loo_Sb = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder") li_BCrlf = 1 loo_Sb.AppendLine("-----BEGIN PUBLIC KEY-----",li_BCrlf) loo_Sb.AppendLine("MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxNbflxUSWQ3XJ1N9dAoh",li_BCrlf) loo_Sb.AppendLine("k+uaiFsg3wkPi9LGS/mH8DtHBgZxKyz+oQBDtnDd9FDEo0ql7MMgCMsTAv27W5vk",li_BCrlf) loo_Sb.AppendLine("Pu0rm6zhcTeYquWEuVCS7VtVsyTATr0Z9WhqNeZlIRurovJAXl2jRDX6QeY5dayC",li_BCrlf) loo_Sb.AppendLine("ubwyG4lBWE4fCakGY6zlh+oaElK0rvblqjYoEg3dn4KPRCYGof8OFxLptHThD4cE",li_BCrlf) loo_Sb.AppendLine("T30j+utVafhO0HRyJ4iR3Pigb4GXdWBtJEEEWddZJizMkjFQkyUAoYLOT8EJ2TW3",li_BCrlf) loo_Sb.AppendLine("Tz8SvAuHBUEFcPWTSTMAG/bSp5wrYBTXaeEhx+wrYa60OruHuzgmhzKyQVuYlCNJ",li_BCrlf) loo_Sb.AppendLine("HdbnassuIRjjSNo25o4AdSlWwpGfBZjAiyEInR+KGpHdhKTxSekJxiwiXUS0UfSG",li_BCrlf) loo_Sb.AppendLine("prOpd5PzWaAR7DvjLsdmR9XffxvJCVxC735gLK7hDJKjCajDPHVDr8FSL8xMlrq0",li_BCrlf) loo_Sb.AppendLine("nKxtsHeRl1yzoGrRr12+9MiQnHtpqROTNXcXdwe3v+Vh8V5k8v8oIrcgh1+/N7Bd",li_BCrlf) loo_Sb.AppendLine("NiRsy1gFHBdu/he/KcDRT/9/acQFMPLQueGfZxUvU5As6pEONjtKX2MUg2fMF6Rc",li_BCrlf) loo_Sb.AppendLine("sQVVrLzg0g7EcuHGfuPeKfD/716MvS8NU7rX+2soijCSQv/e18PJPMVDlcMXjnup",li_BCrlf) loo_Sb.AppendLine("PPx1tStemesavFlj1okhS6UCAwEAAQ==",li_BCrlf) loo_Sb.AppendLine("-----END PUBLIC KEY-----",li_BCrlf) loo_Pubkey = create oleobject // Use "Chilkat_9_5_0.PublicKey" for versions of Chilkat < 10.0.0 li_rc = loo_Pubkey.ConnectToNewObject("Chilkat.PublicKey") li_Success = loo_Pubkey.LoadFromString(loo_Sb.GetAsString()) if li_Success = 0 then Write-Debug loo_Pubkey.LastErrorText destroy loo_Json destroy loo_Dt destroy loo_Sb destroy loo_Pubkey return end if loo_Rsa = create oleobject // Use "Chilkat_9_5_0.Rsa" for versions of Chilkat < 10.0.0 li_rc = loo_Rsa.ConnectToNewObject("Chilkat.Rsa") li_Success = loo_Rsa.ImportPublicKeyObj(loo_Pubkey) if li_Success = 0 then Write-Debug loo_Rsa.LastErrorText destroy loo_Json destroy loo_Dt destroy loo_Sb destroy loo_Pubkey destroy loo_Rsa return end if // 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) loo_Rsa.EncodingMode = "base64url" ls_EncryptedJson = loo_Rsa.EncryptStringENC(loo_Json.Emit(),0) // Build the URL // Such as: https://portal.everyware.com/Account/LoginMenu?data={Base64Url_encrypted_JSON} loo_SbUrl = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbUrl.ConnectToNewObject("Chilkat.StringBuilder") loo_SbUrl.Append("https://portal.everyware.com/Account/LoginMenu?data=") loo_SbUrl.Append(ls_EncryptedJson) Write-Debug loo_SbUrl.GetAsString() destroy loo_Json destroy loo_Dt destroy loo_Sb destroy loo_Pubkey destroy loo_Rsa destroy loo_SbUrl |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.