Android™
Android™
Add a Recipient Certificate for S/MIME Encryption
See more MIME Examples
Demonstrates AddEncryptCert, which adds one recipient certificate to the list used by EncryptN. Call it once for each intended recipient, then call EncryptN to encrypt for all of them.
The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background. AddEncryptCert builds up the recipient list used by EncryptN. Only the public key of each certificate is required for encryption.
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;
CkMime mime = new CkMime();
success = mime.SetBodyFromPlainText("This message will be encrypted.");
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
// AddEncryptCert adds one recipient certificate to the list used by EncryptN. Call it once per
// recipient.
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;
}
// EncryptN then encrypts for all certificates added.
success = mime.EncryptN();
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
Log.i(TAG, "Encrypted for the added recipient(s).");
}
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."
}
}