Sample code for 30+ languages & platforms
Android™

Convert a MIME Part's ASN.1 Body to XML

See more MIME Examples

Demonstrates the Chilkat Mime.AsnBodyToXml method, which parses the current part's decoded body as ASN.1 DER and returns an XML representation of the ASN.1 structure. It takes no arguments.

Tip: Code to parse the returned XML can be generated at Chilkat Tools.

Note: The file path is relative to the application's current working directory. Absolute paths may also be used. Supply the path to your own file.

Background: ASN.1 DER is the binary encoding behind PKCS #7/CMS structures — the signatures and encrypted blobs in S/MIME — and it is opaque to the naked eye. Rendering it as XML exposes the nested structure (content types, certificates, signer info) so you can inspect exactly what a signature or encrypted part contains. It is primarily a diagnostic and learning tool.

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;

    //  Demonstrates the Mime.AsnBodyToXml method, which parses the current part's decoded body as
    //  ASN.1 DER and returns an XML representation of the ASN.1 structure.  It takes no arguments.
    //  This is primarily useful for inspecting binary ASN.1 content such as PKCS #7 structures.

    CkMime mime = new CkMime();
    success = mime.LoadMimeFile("qa_data/pkcs7_part.p7m");
    if (success == false) {
        Log.i(TAG, mime.lastErrorText());
        return;
        }

    String asnXml = mime.asnBodyToXml();
    if (mime.get_LastMethodSuccess() == false) {
        Log.i(TAG, mime.lastErrorText());
        return;
        }

    Log.i(TAG, asnXml);
    //  Code to parse this XML can be generated at Chilkat's online tool:
    //  https://tools.chilkat.io/xmlParse

  }

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