Java
Java
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 Java Downloads
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 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) {
System.out.println(pfx.lastErrorText());
return;
}
System.out.println("Loaded " + pfx.get_NumCerts() + " certificate(s).");
}
}