Sample code for 30+ languages & platforms
Android™

Load .eml and Decrypt (smime.p7m)

Loads an encrypted email from a .eml file and decrypts using certificate w/ private key found in a .p12 (or .pfx) file.

The Content-Type and Content-Disposition email headers of the email to be decrypted look similar to this:

Content-Type: application/x-pkcs7-mime; smime-type=enveloped-data;
	name="smime.p7m"
Content-Disposition: attachment; filename="smime.p7m"

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;

    CkEmail email = new CkEmail();

    // Add a PFX (or .p12) to be used for decryption
    success = email.AddPfxSourceFile("myCert.p12","passwordForP12");
    if (success != true) {
        Log.i(TAG, email.lastErrorText());
        return;
        }

    // Loading the .eml automatically decrypts.
    success = email.LoadEml("encrypted.eml");
    if (success != true) {
        Log.i(TAG, email.lastErrorText());
        return;
        }

    // The email now exists as it was prior to encryption.
    // Your app may access the email's subject, body, attachments,
    // etc. using the Chilkat Email API...

    // Save the decrypted email:
    success = email.SaveEml("decrypted.eml");
    if (success != true) {
        Log.i(TAG, email.lastErrorText());
        return;
        }

    Log.i(TAG, "Success.");

  }

  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."
  }
}