Sample code for 30+ languages & platforms
Java

Example: Crypt2.SetDecryptCert method

Demonstrates how to call the SetDecryptCert method.

Chilkat Java Downloads

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

public class ChilkatExample {

    public static void main(String[] args) {
        Cert cert = new Cert();

        try {
            cert.loadPfxFile("c:/pfx_files/my.pfx", "password");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        Crypt2 decrypt = new Crypt2();
        decrypt.setCryptAlgorithm("pki");

        try {
            decrypt.setDecryptCert(cert);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        BinData bd = new BinData();
        bd.loadFile("c:/someDir/pkcs7_encrypted.dat");

        try {
            decrypt.decryptBd(bd);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // bd contains the decrypted content.
    }
}