Android™
Android™
Load a PFX from BinData
See more PFX/P12 Examples
Demonstrates Pfx.LoadPfxBd, which loads a PFX / PKCS#12 container from the bytes held in a BinData object.
The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.
Background. This is the in-memory equivalent of LoadPfxFile, for when the PKCS#12 data is already available as bytes rather than in a file.
Chilkat Android™ Downloads
// 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 file path is relative to the application's current working directory. An absolute path
// may also be used. Supply the path appropriate to your own environment.
// Load the PFX bytes into a BinData.
CkBinData bd = new CkBinData();
boolean bLoaded = bd.LoadFile("qa_data/identity.pfx");
if (bLoaded != true) {
Log.i(TAG, "Failed to load the PFX file.");
return;
}
// The PFX password should come from a secure source rather than being hard-coded.
String password = "myPfxPassword";
// Load the PFX / PKCS#12 container from the bytes held in the BinData.
success = pfx.LoadPfxBd(bd,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."
}
}