Sample code for 30+ languages & platforms
Java

Example: Crypt2.ClearEncryptCerts method

Demonstrates how to call the ClearEncryptCerts method.

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;

    CkCrypt2 crypt = new CkCrypt2();

    //  Tell the crypt object to use 3 certificates.
    //  Do this by calling AddEncryptCert for each certificate.

    CkCert cert1 = new CkCert();
    //  ...
    //  Load the cert from a source such as a .pfx/.p12 file, smart card, USB token, Apple keychain, Windows certificate store, etc.
    //  ...
    crypt.AddEncryptCert(cert1);

    CkCert cert2 = new CkCert();
    //  ...
    crypt.AddEncryptCert(cert2);

    CkCert cert3 = new CkCert();
    //  ...
    crypt.AddEncryptCert(cert3);

    //  Params for public-key encryption to create PKCS7 enveloped-data
    crypt.put_CryptAlgorithm("pki");
    crypt.put_Pkcs7CryptAlg("aes");
    crypt.put_KeyLength(256);
    crypt.put_OaepHash("sha256");
    crypt.put_OaepPadding(true);

    CkBinData bd = new CkBinData();
    //  ...
    success = crypt.EncryptBd(bd);

    //  Let's say we now want to encrypt something else with different certs..
    //  First clear the encryption certs.
    crypt.ClearEncryptCerts();

    CkCert cert4 = new CkCert();
    //  ...
    crypt.AddEncryptCert(cert4);

    CkCert cert5 = new CkCert();
    //  ...
    crypt.AddEncryptCert(cert5);

    //  ...
    //  ...

    //  Encrypt using cert4 and cert5.
    success = crypt.EncryptBd(bd);
  }
}