Android™
Android™
Get the Certificate an Email Was Encrypted By
See more Email Object Examples
Demonstrates the read-only Chilkat Email.EncryptedBy property. If the email was received encrypted, this property contains descriptive details of the certificate used for encryption. It is meaningful only when ReceivedEncrypted is true. To obtain a certificate object rather than descriptive text, use GetEncryptedByCert or LastDecryptCert. This example loads a received email and prints the encryption certificate details.
Background: In S/MIME encryption, the sender encrypts the message using the recipient's public-key certificate — a signed document that binds an identity (name and email) to a public key.
EncryptedBy reports which certificate was used, letting the recipient confirm the message was encrypted specifically for them. To work with the certificate programmatically (inspecting its subject, issuer, expiration, etc.), request the Cert object via GetEncryptedByCert.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 Email.EncryptedBy property.
// If the email was received encrypted, EncryptedBy contains the details of
// the certificate used for encryption. It is only meaningful when
// ReceivedEncrypted is true.
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) {
Log.i(TAG, "Encrypted by: " + email.encryptedBy());
}
else {
Log.i(TAG, "This email was not received encrypted.");
}
}
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."
}
}