Sample code for 30+ languages & platforms
Android™

Load a PFX from an Encoded String

See more PFX/P12 Examples

Demonstrates Pfx.LoadPfxEncoded, which decodes text using a named binary encoding (such as base64) and loads the resulting bytes as a PFX / PKCS#12 container.

Background. This is useful when the PKCS#12 data has been transported or stored as printable text, such as base64.

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;

    CkPfx pfx = new CkPfx();

    //  The PFX password should come from a secure source rather than being hard-coded.
    String password = "myPfxPassword";

    //  Decode the base64 text into PFX / PKCS#12 bytes and load them.  Common encodings include base64
    //  and hex.
    String encodedPfx = "MIIKrAIBAzCCCm...base64-encoded-pfx...";
    success = pfx.LoadPfxEncoded(encodedPfx,"base64",password);
    if (success == false) {
        Log.i(TAG, pfx.lastErrorText());
        return;
        }

    Log.i(TAG, "Loaded " + String.valueOf(pfx.get_NumCerts()) + " certificate(s).");

  }

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