Android™
Android™
Clear the Encryption Certificates of an Email
See more Email Object Examples
Demonstrates the Chilkat Email.ClearEncryptCerts method, which clears the internal list of explicitly specified certificates used when sending encrypted email — the certificates previously added with AddEncryptCert or SetEncryptCert. This example adds a recipient certificate and then clears the list.
Background: When encrypting to multiple recipients you register each one's certificate with
AddEncryptCert. If an Email object is reused for different sets of recipients, those registered certificates would otherwise persist. ClearEncryptCerts resets that list so the next encrypted message is protected for exactly the intended recipients — a useful safeguard against accidentally encrypting for a stale recipient.Chilkat Android™ Downloads
// 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;
// Demonstrates the ClearEncryptCerts method, which clears the internal list of explicitly
// specified certificates used for sending encrypted email (the certificates added by
// AddEncryptCert / SetEncryptCert).
CkEmail email = new CkEmail();
// Add a recipient certificate to the encryption cert list...
CkCert cert = new CkCert();
success = cert.LoadFromFile("qa_data/certs/recipient.cer");
if (success == false) {
Log.i(TAG, cert.lastErrorText());
return true;
}
success = email.AddEncryptCert(cert);
if (success == false) {
Log.i(TAG, email.lastErrorText());
return true;
}
// ...then clear all explicitly-specified encryption certificates.
email.ClearEncryptCerts();
Log.i(TAG, "Cleared the explicitly-specified encryption certificates.");
// Note: The path "qa_data/certs/recipient.cer" is a relative local filesystem path,
// relative to the current working directory of the running application.
}
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."
}
}