Android™
Android™
Provide a Certificate Vault to an Email
See more Email Object Examples
Demonstrates the Chilkat Email.UseCertVault method, which adds an XML certificate vault to the email's internal certificate and private-key lookup sources for encryption, decryption, signing, and verification. This example builds a vault from a PFX and attaches it to the email.
Background: A certificate vault is a portable, in-memory store of certificates and private keys. Instead of wiring up each certificate individually for every operation, you load your credentials into one
XmlCertVault and hand it to the email; Chilkat then draws on it automatically whenever it needs a key — to decrypt an incoming message, sign an outgoing one, or verify a signature. This is especially convenient on platforms without an OS certificate store.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 UseCertVault method, which adds an XML certificate vault to the email's
// internal certificate and private-key lookup sources for encryption, decryption, signing,
// and verification.
CkEmail email = new CkEmail();
// Build a certificate vault from a PFX (certificate + private key).
CkXmlCertVault vault = new CkXmlCertVault();
success = vault.AddPfxFile("qa_data/certs/certs.pfx","pfx_password");
if (success == false) {
Log.i(TAG, vault.lastErrorText());
return true;
}
// Make the vault available to the email object for crypto operations.
success = email.UseCertVault(vault);
if (success == false) {
Log.i(TAG, email.lastErrorText());
return true;
}
Log.i(TAG, "Certificate vault attached to the email.");
// Note: The path "qa_data/certs/certs.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."
}
}