Sample code for 30+ languages & platforms
Objective-C

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 Objective-C Downloads

Objective-C
#import <CkoMime.h>
#import <CkoCert.h>

BOOL success = NO;

CkoMime *mime = [[CkoMime alloc] init];
success = [mime SetBodyFromPlainText: @"This message will be encrypted."];
if (success == NO) {
    NSLog(@"%@",mime.LastErrorText);
    return;
}

//  Add a recipient certificate.
CkoCert *cert = [[CkoCert alloc] init];
success = [cert LoadFromFile: @"qa_data/recipient.cer"];
if (success == NO) {
    NSLog(@"%@",cert.LastErrorText);
    return;
}

success = [mime AddEncryptCert: cert];
if (success == NO) {
    NSLog(@"%@",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];

NSLog(@"%@",@"Recipient certificate list cleared.");