Sample code for 30+ languages & platforms
Android™

Check for an S/MIME Signing Time

See more MIME Examples

Demonstrates the Chilkat Mime.HasSignatureSigningTime method, which returns whether the signer at a zero-based index included a CMS signingTime signed attribute. The only argument is the signer index; use NumSignerCerts for the count.

Note: 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: A signing time records when the signer claims to have signed, which matters for auditing and for validating a certificate that has since expired. It is an optional signed attribute, so not every signature has one — this predicate lets you check before calling GetSignatureSigningTimeStr, avoiding an error for signers that omitted it. Being a signed attribute, it is covered by the signature and cannot be altered undetected.

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;

    CkMime mime = new CkMime();
    success = mime.LoadMimeFile("qa_data/signed.eml");
    if (success == false) {
        Log.i(TAG, mime.lastErrorText());
        return;
        }

    //  After verifying, check whether each signer included a CMS signingTime signed attribute.  The
    //  only argument is the zero-based signer index.
    success = mime.Verify();
    if (success != true) {
        Log.i(TAG, mime.lastErrorText());
        return;
        }

    int n = mime.get_NumSignerCerts();
    int i;
    for (i = 0; i <= n - 1; i++) {
        if (mime.HasSignatureSigningTime(i)) {
            Log.i(TAG, "Signer " + String.valueOf(i) + " included a signing time.");
            }
        else {
            Log.i(TAG, "Signer " + String.valueOf(i) + " did not include a signing time.");
            }

        }


  }

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