Android™
Android™
Get the S/MIME Signer's Certificate
See more MIME Examples
Demonstrates the Chilkat Mime.LastSignerCert method, which loads the signer certificate at a zero-based index from the most recent successful verification (or security-unwrapping) into a Cert. The first argument is the signer index and the second is the receiving Cert.
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: Verifying tells you the signature is mathematically valid, but you usually also need to know who signed — the subject, the issuer, the validity dates — to decide whether to trust it. This retrieves each signer's certificate after verification so your code can inspect and apply its own trust rules. A message can have multiple signers, so iterate from
0 to NumSignerCerts - 1.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.LoadMimeFile("qa_data/signed.eml");
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
// After a successful verification, load each signer's certificate to inspect it. The 1st argument
// is the zero-based signer index and the 2nd is a Cert object that receives the certificate.
success = mime.Verify();
if (success != true) {
Log.i(TAG, mime.lastErrorText());
return;
}
int n = mime.get_NumSignerCerts();
CkCert cert = new CkCert();
int i;
for (i = 0; i <= n - 1; i++) {
success = mime.LastSignerCert(i,cert);
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
Log.i(TAG, "Signer " + String.valueOf(i) + ": " + cert.subjectCN() + " (issued by " + cert.issuerCN() + ")");
}
}
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."
}
}