Sample code for 30+ languages & platforms
Swift

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 Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let mime = CkoMime()!
    success = mime.setBody(fromPlainText: "This message will be encrypted.")
    if success == false {
        print("\(mime.lastErrorText!)")
        return
    }

    //  Add a recipient certificate.
    let cert = CkoCert()!
    success = cert.load(fromFile: "qa_data/recipient.cer")
    if success == false {
        print("\(cert.lastErrorText!)")
        return
    }

    success = mime.addEncryptCert(cert: cert)
    if success == false {
        print("\(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()

    print("Recipient certificate list cleared.")

}