Sample code for 30+ languages & platforms
Java

Verify and Unwrap PCKS7 Signed MIME

See more MIME Examples

Demonstrates calling the Verify method to verify and unwrap PKCS7 signed MIME. The MIME is restored to the original structure that it would have originally had prior to signing. The Verify method works with both detached signatures, as well as opaque/attached signatures.

Chilkat Java Downloads

Java
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;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkMime mime = new CkMime();

    // A PKCS7 signature usually embeds both the signing
    // certificate with its public key.  Therefore, it is usually 
    // possible to verify a signature without the need to 
    // already have the certificate installed.

    // Load the signed MIME from a file...
    success = mime.LoadMimeFile("signedMime.txt");
    if (success == false) {
        System.out.println(mime.lastErrorText());
        return;
        }

    // Verify the signed MIME and restore the MIME
    // to the structure/content it had prior to signing.
    boolean verified;
    verified = mime.Verify();
    if (verified == false) {
        System.out.println(mime.lastErrorText());
        return;
        }

    // Examine the MIME after signature verification (i.e. "unwrapping")
    System.out.println(mime.getMime());
  }
}