Java
Chilkat2 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.chilkat2.Cert;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Mime;
public class ChilkatExample {
public static void main(String[] args) {
Mime mime = new Mime();
try {
mime.setBodyFromPlainText("This message will be encrypted.");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Add a recipient certificate.
Cert cert = new Cert();
try {
cert.loadFromFile("qa_data/recipient.cer");
mime.addEncryptCert(cert);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
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.");
}
}