Android™
Android™
Get PDF Signer Certs
See more PDF Signatures Examples
This example demonstrates how to validate the signatures in a PDF and also shows how to getChilkat 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;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkPdf pdf = new CkPdf();
// Load a PDF that has cryptographic signatures to be validated
success = pdf.LoadFile("qa_data/pdf/sign_testing_1/helloSigned2.pdf");
if (success == false) {
Log.i(TAG, pdf.lastErrorText());
return;
}
// Each time we verify a signature, information about the signature is written into
// sigInfo (replacing whatever sigInfo previously contained).
CkJsonObject sigInfo = new CkJsonObject();
// Iterate over each signature and validate each.
int numSignatures = pdf.get_NumSignatures();
boolean validated = false;
CkCert cert = new CkCert();
int i = 0;
while (i < numSignatures) {
validated = pdf.VerifySignature(i,sigInfo);
Log.i(TAG, "Signature " + String.valueOf(i) + " validated: " + String.valueOf(validated));
// After calling VerifySignature, you can get the signer certificate by calling
// GetSignerCert with the same index.
success = pdf.GetSignerCert(i,cert);
if (success != false) {
Log.i(TAG, "PDF signer certificate: " + cert.subjectDN());
}
i = i + 1;
}
Log.i(TAG, "Finished.");
}
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."
}
}