Sample code for 30+ languages & platforms
Java

Example: Crypt2.GetSignedAttributes method

Demonstrates how to call the GetSignedAttributes method.

Chilkat Java Downloads

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

public class ChilkatExample {

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

        BinData bdPkcs7 = new BinData();
        try {
            bdPkcs7.loadFile("qa_data/cades/CAdES-T/Signature-C-T-1.p7m");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        JsonObject json = new JsonObject();
        json.setEmitCompact(false);

        StringBuilder sbJson = new StringBuilder();
        int i = 0;
        boolean tryNext = true;
        while (tryNext) {
            if (crypt.getSignedAttributes(i, bdPkcs7, sbJson)) {
                json.loadSb(sbJson);
                System.out.println(i + ": ");
                System.out.println(json.emit());
            } else {
                tryNext = false;
            }

            i = i + 1;
        }

        // Sample output:

        // 0:
        // {
        //   "signedAttributes": [
        //     {
        //       "oid": "1.2.840.113549.1.9.3",
        //       "name": "Content Type"
        //     },
        //     {
        //       "oid": "1.2.840.113549.1.9.5",
        //       "name": "Signing Time"
        //     },
        //     {
        //       "oid": "1.2.840.113549.1.9.4",
        //       "name": "Message Digest"
        //     },
        //     {
        //       "oid": "1.2.840.113549.1.9.16.2.47",
        //       "name": "Signing Certificate V2"
        //     }
        //   ]
        // }
    }
}