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™) JWE using ECDH-ES, BP-256, A256GCMSee more JSON Web Encryption (JWE) ExamplesCreate a JWE with the following header: { "alg": "ECDH-ES", "enc": "A256GCM", "exp": 1621957030, "cty": "NJWT", "epk": { "kty": "EC", "x": "QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w" "y": "AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu" "crv": "BP-256" } } Note: This example requires Chilkat v9.5.0.87 or greater.
// 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 requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. boolean success; // Load our brainpool BP-256 public key. // { // "use": "enc", // "kid": "puk_idp_enc", // "kty": "EC", // "crv": "BP-256", // "x": "QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w", // "y": "AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu" // } CkJsonObject json = new CkJsonObject(); json.UpdateString("use","enc"); json.UpdateString("kid","puk_idp_enc"); json.UpdateString("kty","EC"); json.UpdateString("crv","BP-256"); json.UpdateString("x","QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w"); json.UpdateString("y","AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu"); CkPublicKey pubkey = new CkPublicKey(); success = pubkey.LoadFromString(json.emit()); if (success == false) { Log.i(TAG, pubkey.lastErrorText()); return; } // Build our protected header: // { // "alg": "ECDH-ES", // "enc": "A256GCM", // "exp": 1621957030, // "cty": "NJWT", // "epk": { // "kty": "EC", // "x": "QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w" // "y": "AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu" // "crv": "BP-256" // } // } // Use jwt only for getting the current date/time + 3600 seconds. CkJwt jwt = new CkJwt(); CkJsonObject jweProtHdr = new CkJsonObject(); jweProtHdr.UpdateString("alg","ECDH-ES"); jweProtHdr.UpdateString("enc","A256GCM"); jweProtHdr.UpdateInt("exp",jwt.GenNumericDate(3600)); jweProtHdr.UpdateString("cty","NJWT"); jweProtHdr.UpdateString("epk.kty","EC"); jweProtHdr.UpdateString("epk.x","QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w"); jweProtHdr.UpdateString("epk.y","AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu"); jweProtHdr.UpdateString("epk.crv","BP-256"); CkJwe jwe = new CkJwe(); jwe.SetProtectedHeader(jweProtHdr); jwe.SetPublicKey(0,pubkey); String plainText = "This is the text to be encrypted."; String strJwe = jwe.encrypt(plainText,"utf-8"); if (jwe.get_LastMethodSuccess() != true) { Log.i(TAG, jwe.lastErrorText()); return; } Log.i(TAG, strJwe); Log.i(TAG, "Success."); } 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.