CkJava Requires Chilkat v11.8.0+
CkJava
Inspect S/MIME protection when loading an email
See more Email Object Examples
Load a signed or encrypted message and inspect each layer the parser encountered. Register the recipient's certificate and private key first (AddPemSource) for encrypted input. SignaturesValid reports the cryptographic verification result. Applications that rely on signer identity must also validate the certificate and their trust policy.
Chilkat CkJava Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkEmail email = new CkEmail();
// For encrypted input, register the matching certificate and private key (here from a PEM file)
// before LoadEml:
// new Pem pem;
// success = pem.LoadPemFile("recipient.pem","PEM_PASSWORD");
// success = email.AddPemSource(pem);
success = email.LoadEml("signed.eml");
if (success != true) {
System.out.println(email.lastErrorText());
return;
}
System.out.println("Encryption layer present: " + email.get_ReceivedEncrypted());
if (email.get_ReceivedEncrypted() == true) {
System.out.println("Decrypted: " + email.get_Decrypted());
}
System.out.println("Signature layer present: " + email.get_ReceivedSigned());
if (email.get_ReceivedSigned() == true) {
System.out.println("Signature verified: " + email.get_SignaturesValid());
if (email.get_SignaturesValid() == true) {
System.out.println("Signer: " + email.signedBy());
}
}
}
}