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

Chilkat2 Java
import com.chilkatsoft.chilkat2.BinData;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Pfx;

public class ChilkatExample {

    public static void main(String[] args) {
        Pfx pfx = new Pfx();

        // 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.
        BinData bd = new BinData();
        try {
            bd.loadFile("qa_data/identity.pfx");
        } catch (ChilkatException e) {
            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.
        try {
            pfx.loadPfxBd(bd, password);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

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