Sample code for 30+ languages & platforms
Android™

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 Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean success = false;

    CkMime mime = new CkMime();
    success = mime.SetBodyFromPlainText("This message will be encrypted.");
    if (success == false) {
        Log.i(TAG, mime.lastErrorText());
        return;
        }

    //  Add a recipient certificate.
    CkCert cert = new CkCert();
    success = cert.LoadFromFile("qa_data/recipient.cer");
    if (success == false) {
        Log.i(TAG, cert.lastErrorText());
        return;
        }

    success = mime.AddEncryptCert(cert);
    if (success == false) {
        Log.i(TAG, 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();

    Log.i(TAG, "Recipient certificate list cleared.");

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}