Java
Java
Clear the S/MIME Recipient Certificate List
See more MIME Examples
Demonstrates ClearEncryptCerts, which empties the recipient-certificate list previously populated by AddEncryptCert. This is useful to start over with a different set of recipients before calling EncryptN.
Background. The recipient list is internal state that accumulates across AddEncryptCert calls. ClearEncryptCerts resets it so a subsequent EncryptN encrypts only for the certificates added afterward.
Chilkat Java Downloads
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;
CkMime mime = new CkMime();
success = mime.SetBodyFromPlainText("This message will be encrypted.");
if (success == false) {
System.out.println(mime.lastErrorText());
return;
}
// Add a recipient certificate.
CkCert cert = new CkCert();
success = cert.LoadFromFile("qa_data/recipient.cer");
if (success == false) {
System.out.println(cert.lastErrorText());
return;
}
success = mime.AddEncryptCert(cert);
if (success == false) {
System.out.println(mime.lastErrorText());
return;
}
// ClearEncryptCerts empties the recipient-certificate list, for example to start over with a
// different set of recipients before calling EncryptN. It is a void method.
mime.ClearEncryptCerts();
System.out.println("Recipient certificate list cleared.");
}
}