Android™
Android™
Set the Signing Certificate for an Email
See more Email Object Examples
Demonstrates the Chilkat Email.SetSigningCert method, which sets the certificate (with access to its private key) used to create a digital signature when sending signed email. This example loads the signing certificate from a PFX, sets it, and enables signed sending.
Background: Signing uses your own private key (the opposite of encrypting, which uses the recipient's public key), so the signing certificate must include private-key access. A PFX (PKCS#12) file bundles the certificate and its private key together, which is why it is loaded here with
LoadPfxFile. If the certificate and key are in separate files, use SetSigningCert2 instead.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 SetSigningCert method, which sets the certificate (with access to its
// private key) used for creating a digital signature when sending signed email.
CkEmail email = new CkEmail();
email.put_Subject("Signed email");
email.put_Body("This message will be sent with a digital signature.");
email.put_From("alice@example.com");
email.AddTo("Bob","bob@example.com");
// Load a signing certificate together with its private key from a PFX file.
CkCert cert = new CkCert();
success = cert.LoadPfxFile("qa_data/certs/signer.pfx","pfx_password");
if (success == false) {
Log.i(TAG, cert.lastErrorText());
return true;
}
// Set the certificate used to create the signature.
success = email.SetSigningCert(cert);
if (success == false) {
Log.i(TAG, email.lastErrorText());
return true;
}
// Request that the email be sent with a digital signature.
email.put_SendSigned(true);
Log.i(TAG, "Signing certificate set.");
// Note: The path "qa_data/certs/signer.pfx" 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."
}
}