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
(Android™) 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
// Important: Don't forget to include the call to System.loadLibrary // as shown at the bottom of this code sample. package com.test; import android.app.Activity; import com.chilkatsoft.*; import android.widget.TextView; import android.os.Bundle; public class SimpleActivity extends Activity { private static final String TAG = "Chilkat"; // Called when the activity is first created. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. boolean success; // First build the JSON to be encrypted. CkJsonObject json = new CkJsonObject(); json.UpdateString("provider_key","USER GUID HERE"); json.UpdateString("menu_item","payment"); CkDateTime dt = new CkDateTime(); dt.SetFromCurrentSystemTime(); json.UpdateString("date_time",dt.getAsUnixTimeStr(false)); // 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 json.put_EmitCompact(true); // Everyware's RSA public key is at: https://docs.everyware.com/docs/everyware-public-rsa-key CkStringBuilder sb = new CkStringBuilder(); boolean bCrlf = true; sb.AppendLine("-----BEGIN PUBLIC KEY-----",bCrlf); sb.AppendLine("MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxNbflxUSWQ3XJ1N9dAoh",bCrlf); sb.AppendLine("k+uaiFsg3wkPi9LGS/mH8DtHBgZxKyz+oQBDtnDd9FDEo0ql7MMgCMsTAv27W5vk",bCrlf); sb.AppendLine("Pu0rm6zhcTeYquWEuVCS7VtVsyTATr0Z9WhqNeZlIRurovJAXl2jRDX6QeY5dayC",bCrlf); sb.AppendLine("ubwyG4lBWE4fCakGY6zlh+oaElK0rvblqjYoEg3dn4KPRCYGof8OFxLptHThD4cE",bCrlf); sb.AppendLine("T30j+utVafhO0HRyJ4iR3Pigb4GXdWBtJEEEWddZJizMkjFQkyUAoYLOT8EJ2TW3",bCrlf); sb.AppendLine("Tz8SvAuHBUEFcPWTSTMAG/bSp5wrYBTXaeEhx+wrYa60OruHuzgmhzKyQVuYlCNJ",bCrlf); sb.AppendLine("HdbnassuIRjjSNo25o4AdSlWwpGfBZjAiyEInR+KGpHdhKTxSekJxiwiXUS0UfSG",bCrlf); sb.AppendLine("prOpd5PzWaAR7DvjLsdmR9XffxvJCVxC735gLK7hDJKjCajDPHVDr8FSL8xMlrq0",bCrlf); sb.AppendLine("nKxtsHeRl1yzoGrRr12+9MiQnHtpqROTNXcXdwe3v+Vh8V5k8v8oIrcgh1+/N7Bd",bCrlf); sb.AppendLine("NiRsy1gFHBdu/he/KcDRT/9/acQFMPLQueGfZxUvU5As6pEONjtKX2MUg2fMF6Rc",bCrlf); sb.AppendLine("sQVVrLzg0g7EcuHGfuPeKfD/716MvS8NU7rX+2soijCSQv/e18PJPMVDlcMXjnup",bCrlf); sb.AppendLine("PPx1tStemesavFlj1okhS6UCAwEAAQ==",bCrlf); sb.AppendLine("-----END PUBLIC KEY-----",bCrlf); CkPublicKey pubkey = new CkPublicKey(); success = pubkey.LoadFromString(sb.getAsString()); if (success == false) { Log.i(TAG, pubkey.lastErrorText()); return; } CkRsa rsa = new CkRsa(); success = rsa.ImportPublicKeyObj(pubkey); if (success == false) { Log.i(TAG, rsa.lastErrorText()); return; } // 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) rsa.put_EncodingMode("base64url"); String encryptedJson = rsa.encryptStringENC(json.emit(),false); // Build the URL // Such as: https://portal.everyware.com/Account/LoginMenu?data={Base64Url_encrypted_JSON} CkStringBuilder sbUrl = new CkStringBuilder(); sbUrl.Append("https://portal.everyware.com/Account/LoginMenu?data="); sbUrl.Append(encryptedJson); Log.i(TAG, sbUrl.getAsString()); } static { System.loadLibrary("chilkat"); // Note: If the incorrect library name is passed to System.loadLibrary, // then you will see the following error message at application startup: //"The application <your-application-name> has stopped unexpectedly. Please try again." } } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.