Sample code for 30+ languages & platforms
Android™ Requires Chilkat v11.0.0+

Sign an EML using RSA-PSS and SHA-256

See more Email Object Examples

Load the intended signing certificate and its RSA private key from a PFX. Set the signature options on Email and render the final S/MIME message through MailMan. The resulting multipart/signed file can be verified independently. Supply the PFX password through your application’s credential store.

Chilkat Android™ Downloads

Android™
// 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;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    CkEmail email = new CkEmail();
    success = email.LoadEml("message.eml");
    if (success != true) {
        Log.i(TAG, email.lastErrorText());
        return;
        }

    CkCert cert = new CkCert();
    success = cert.LoadPfxFile("signer.pfx","PFX_PASSWORD");
    if (success != true) {
        Log.i(TAG, cert.lastErrorText());
        return;
        }

    success = email.SetSigningCert(cert);
    if (success != true) {
        Log.i(TAG, email.lastErrorText());
        return;
        }

    email.put_SigningAlg("pss");
    email.put_SigningHashAlg("sha256");
    email.put_SendSigned(true);
    CkMailMan mail = new CkMailMan();
    mail.put_OpaqueSigning(false);
    CkBinData rendered = new CkBinData();
    success = mail.RenderToMimeBd(email,rendered);
    if (success != true) {
        Log.i(TAG, mail.lastErrorText());
        return;
        }

    success = rendered.WriteFile("signed.eml");
    if (success != true) {
        Log.i(TAG, "Failed: rendered.WriteFile.");
        return;
        }

    Log.i(TAG, "Saved signed.eml.");

  }

  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."
  }
}