Android™
Android™
Example: Mime.GetDecryptCertInfo method
Demonstrates theGetDecryptCertInfo method.
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;
CkMime mime = new CkMime();
// Load MIME that is has Content-Type like this:
// Content-Type: application/pkcs7-mime; smime-type="enveloped-data"; name="smime.p7m"; smime-type="enveloped-data"
success = mime.LoadMimeFile("qa_data/mime/enveloped_data.eml");
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
// Get information about the certificate that would be needed to decrypt.
// An enveloped-data can potentially be decrypted by multiple certificates if it was encrypted in a way that allows it,
// but in most cases, only a single certificate with associated private key (that of the message recipient) is possible.
CkJsonObject json = new CkJsonObject();
success = mime.GetDecryptCertInfo(json);
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
json.put_EmitCompact(false);
Log.i(TAG, json.emit());
// Sample output:
// {
// "recipientInfo": [
// {
// "serial": "****",
// "issuerCN": "****"
// }
// ]
// }
// Get each certificate's information like this:
String serial;
String issuerCN;
int i = 0;
int count = json.SizeOfArray("recipientInfo");
while (i < count) {
json.put_I(i);
serial = json.stringOf("recipientInfo[i].serial");
issuerCN = json.stringOf("recipientInfo[i].issuerCN");
i = i + 1;
}
}
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."
}
}