Sample code for 30+ languages & platforms
Java

Verify the Timestamp Server Token (if any) while Validating a CMS Signature

Demonstrates how to also validate the timestamp server token (if any) while validating a CMS signature.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Crypt2;
import com.chilkatsoft.chilkat2.JsonObject;

public class ChilkatExample {

    public static void main(String[] args) {
        Crypt2 crypt = new Crypt2();

        // Tell Chilkat to also validate the timestamp token if a timestamp exists in the CMS message's unauthenticated attributes.
        JsonObject cmsOptions = new JsonObject();
        cmsOptions.updateBool("ValidateTimestampTokens", true);
        crypt.setCmsOptions(cmsOptions.emit());

        String outputFile = "qa_output/original.xml";
        String inFile = "qa_data/p7m/fattura_signature.xml.p7m";

        // Verify the signature and extract the contained file, which in this case is XML.
        try {
            crypt.verifyP7M(inFile, outputFile);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("Signature validated.");
    }
}