Sample code for 30+ languages & platforms
Android™

Load a Public Key from BinData

Demonstrates the Chilkat PublicKey.LoadBd method, which loads a public key from the bytes in a BinData. The only argument is the BinData, which may contain binary DER or any textual representation recognized by LoadFromString.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: When key bytes are already in memory — downloaded, extracted from a container, or pulled from a database — this loads them directly with no temporary file. It applies the same content inspection as the string and file loaders, so it accepts both binary DER and any recognized text form. It is the in-memory counterpart to LoadFromFile.

Chilkat Android™ Downloads

Android™
// 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);

    boolean success = false;

    //  Demonstrates the PublicKey.LoadBd method, which loads a public key from the bytes in a BinData.
    //  The only argument is the BinData, which may contain binary DER or any textual representation
    //  recognized by LoadFromString.

    CkBinData bd = new CkBinData();
    success = bd.LoadFile("qa_data/public.der");
    if (success == false) {
        Log.i(TAG, bd.lastErrorText());
        return;
        }

    CkPublicKey pubKey = new CkPublicKey();
    success = pubKey.LoadBd(bd);
    if (success == false) {
        Log.i(TAG, pubKey.lastErrorText());
        return;
        }

    Log.i(TAG, "Loaded a " + pubKey.keyType() + " public key.");

  }

  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."
  }
}