Android™
Android™
Get the Certificate Used to Decrypt an Email
See more Email Object Examples
Demonstrates the Chilkat Email.LastDecryptCert method, which copies the certificate used to decrypt this email into a Cert object. It should be called after a successful decryption. This example loads an encrypted email and, if it was decrypted, reads the decrypting certificate's common name.
Background: When a message could be decrypted with one of several available private keys, it is often useful to know which certificate actually did the job — for auditing, for confirming the message was encrypted for the expected identity, or for logging.
LastDecryptCert hands you that certificate as an object so you can inspect its subject, issuer, validity dates, and more.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;
// Demonstrates the LastDecryptCert method, which copies the certificate used to decrypt
// this email into a Cert object. Call it after a successful decryption.
CkEmail email = new CkEmail();
success = email.LoadEml("qa_data/eml/encrypted.eml");
if (success == false) {
Log.i(TAG, email.lastErrorText());
return true;
}
if (email.get_ReceivedEncrypted() == true) {
if (email.get_Decrypted() == true) {
// Get the certificate that was used to decrypt the email.
CkCert cert = new CkCert();
success = email.LastDecryptCert(cert);
if (success == true) {
Log.i(TAG, "Decrypted with 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."
}
}