Sample code for 30+ languages & platforms
Java

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 Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    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) {
        System.out.println("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) {
        System.out.println(pfx.lastErrorText());
        return;
        }

    System.out.println("Loaded " + pfx.get_NumCerts() + " certificate(s).");
  }
}