Sample code for 30+ languages & platforms
CkJava Requires Chilkat v11.8.0+

Example: Crypt2.AddPemSource method

Demonstrates how to call the AddPemSource method.

Chilkat CkJava Downloads

CkJava
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;

    CkCrypt2 crypt = new CkCrypt2();
    success = false;

    //  Do public-key decryption (RSA)
    crypt.put_CryptAlgorithm("pki");

    //  ...
    //  ...
    //  ...

    //  Load a PEM file that has a certificate and its private key.  The 2nd argument of LoadPemFile
    //  is the password of the private key.  (Pass an empty string if the private key is not encrypted.)
    String pemPath = "c:/my_pem_files/a.pem";
    String pemPassword = "secret1";
    CkPem pem = new CkPem();
    success = pem.LoadPemFile(pemPath,pemPassword);
    if (success == false) {
        System.out.println(pem.lastErrorText());
        return;
        }

    success = crypt.AddPemSource(pem);
    if (success == false) {
        System.out.println(crypt.lastErrorText());
        return;
        }

    //  Add as many PEM sources as desired...
    //  Each call to AddPemSource adds more certificates to the ones already added.
    pemPath = "c:/my_pem_files/b.pem";
    pemPassword = "secret2";
    CkPem pem2 = new CkPem();
    success = pem2.LoadPemFile(pemPath,pemPassword);
    if (success == false) {
        System.out.println(pem2.lastErrorText());
        return;
        }

    success = crypt.AddPemSource(pem2);
    if (success == false) {
        System.out.println(crypt.lastErrorText());
        return;
        }

    //  ...
    //  ...
  }
}