Sample code for 30+ languages & platforms
Java

Example: Crypt2.SetDecryptCert method

Demonstrates how to call the SetDecryptCert 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;

    CkCert cert = new CkCert();

    success = cert.LoadPfxFile("c:/pfx_files/my.pfx","password");
    if (success != true) {
        System.out.println(cert.lastErrorText());
        return;
        }

    CkCrypt2 decrypt = new CkCrypt2();
    decrypt.put_CryptAlgorithm("pki");

    success = decrypt.SetDecryptCert(cert);
    if (success != true) {
        System.out.println(decrypt.lastErrorText());
        return;
        }

    CkBinData bd = new CkBinData();
    success = bd.LoadFile("c:/someDir/pkcs7_encrypted.dat");

    success = decrypt.DecryptBd(bd);
    if (success != true) {
        System.out.println(decrypt.lastErrorText());
        return;
        }

    //  bd contains the decrypted content.
  }
}