Sample code for 30+ languages & platforms
Android™

Get the Signer Certificate of a Signed Email

See more Email Object Examples

Demonstrates the Chilkat Email.LastSignerCert method, which copies the certificate for the signer at a given zero-based index into a Cert object. Most signed emails have one signer (index 0), but a message can have more than one. This example loads a signed email and reads the first signer's common name.

Background: Confirming that a signature is valid (see SignaturesValid) tells you the content wasn't altered, but not who signed it. LastSignerCert gives you the signer's certificate as an object so you can examine its subject and issuer and evaluate trust — an essential step before relying on a signature to establish the sender's identity.

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 LastSignerCert method, which copies the certificate for the signer at
    //  the given zero-based index into a Cert object.  Most signed emails have one signer
    //  (index 0), but a message can have more than one.

    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) {
        //  Get the certificate of the first signer (index 0).
        CkCert cert = new CkCert();
        success = email.LastSignerCert(0,cert);
        if (success == true) {
            Log.i(TAG, "Signer certificate (CN): " + cert.subjectCN());
            }

        }

    //  Note: The path "qa_data/..." 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."
  }
}