Sample code for 30+ languages & platforms
Android™

Check if an Email Was Received Digitally Signed

See more Email Object Examples

Demonstrates the read-only Chilkat Email.ReceivedSigned property, which is true if the email was originally received carrying one or more digital signatures. Knowing a message was signed is separate from knowing the signature checked out, so this example also reads SignaturesValid to report whether the signed content verified.

Background: A digital signature on an email (S/MIME) provides two things: authenticity (it was really sent by the holder of a particular certificate) and integrity (the content was not altered in transit). The sender signs a hash of the message with their private key; the recipient verifies it with the sender's public certificate. ReceivedSigned simply tells you a signature is present — verifying it is a separate step exposed through SignaturesValid.

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;

    //  Demonstrates the read-only Email.ReceivedSigned property, which is true if this
    //  email was originally received with a digital signature.  Use SignaturesValid to
    //  determine whether the signed content actually verified.

    CkEmail email = new CkEmail();

    success = email.LoadEml("qa_data/eml/signed.eml");
    if (success == false) {
        Log.i(TAG, email.lastErrorText());
        return true;
        }

    if (email.get_ReceivedSigned() == true) {
        Log.i(TAG, "This email was received with a digital signature.");
        if (email.get_SignaturesValid() == true) {
            Log.i(TAG, "All signatures are valid.");
            }
        else {
            Log.i(TAG, "One or more signatures are NOT valid.");
            }

        }
    else {
        Log.i(TAG, "This email was not signed.");
        }

    //  Note: Paths such as "qa_data/..." are relative local filesystem paths,
    //  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."
  }
}