Sample code for 30+ languages & platforms
Java

Example: Crypt2.ClearEncryptCerts method

Demonstrates how to call the ClearEncryptCerts method.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.BinData;
import com.chilkatsoft.chilkat2.Cert;
import com.chilkatsoft.chilkat2.Crypt2;

public class ChilkatExample {

    public static void main(String[] args) {
        Crypt2 crypt = new Crypt2();

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

        Cert cert1 = new Cert();
        // ...
        // 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);

        Cert cert2 = new Cert();
        // ...
        crypt.addEncryptCert(cert2);

        Cert cert3 = new Cert();
        // ...
        crypt.addEncryptCert(cert3);

        // Params for public-key encryption to create PKCS7 enveloped-data
        crypt.setCryptAlgorithm("pki");
        crypt.setPkcs7CryptAlg("aes");
        crypt.setKeyLength(256);
        crypt.setOaepHash("sha256");
        crypt.setOaepPadding(true);

        BinData bd = new BinData();
        // ...
        crypt.encryptBd(bd);

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

        Cert cert4 = new Cert();
        // ...
        crypt.addEncryptCert(cert4);

        Cert cert5 = new Cert();
        // ...
        crypt.addEncryptCert(cert5);

        // ...
        // ...

        // Encrypt using cert4 and cert5.
        crypt.encryptBd(bd);
    }
}