Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Get PDF DSS (Document Security Store)See more PDF Signatures ExamplesThis example demonstrates how to extract the information from a PDF's DSS (Document Security Store), if a /DSS exists. (Just because a PDF is signed does not mean a /DSS will exists. In fact, the /DSS is typically created at the point of adding the 2nd or greater signature because the /DSS contains LTV (long term validation) information about the previous signature at the time of adding an additional signature.) Note: This example requires Chilkat v9.5.0.85 or greater.
#include <C_CkPdfW.h> #include <C_CkJsonObjectW.h> #include <C_CkDtObjW.h> void ChilkatSample(void) { HCkPdfW pdf; BOOL success; HCkJsonObjectW json; HCkDtObjW responseDateTime; HCkDtObjW thisUpdate; HCkDtObjW nextUpdate; const wchar_t *serial; const wchar_t *validFrom; const wchar_t *validTo; BOOL expired; const wchar_t *subjectCN; const wchar_t *subjectO; const wchar_t *issuerCN; const wchar_t *issuerO; const wchar_t *keyType; const wchar_t *keySize; const wchar_t *der; const wchar_t *subjectOU; const wchar_t *subjectC; const wchar_t *issuerOU; const wchar_t *issuerC; int responseStatus; const wchar_t *responseTypeOid; const wchar_t *responseTypeName; const wchar_t *responseResponderIdChoice; const wchar_t *responseResponderKeyHash; int j; int count_j; const wchar_t *hashOid; const wchar_t *hashAlg; const wchar_t *issuerNameHash; const wchar_t *issuerKeyHash; const wchar_t *serialNumber; int status; int i; int count_i; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. pdf = CkPdfW_Create(); success = CkPdfW_LoadFile(pdf,L"qa_data/pdf/sign_testing_1/helloSigned2.pdf"); if (success == FALSE) { wprintf(L"%s\n",CkPdfW_lastErrorText(pdf)); CkPdfW_Dispose(pdf); return; } json = CkJsonObjectW_Create(); CkJsonObjectW_putEmitCompact(json,FALSE); success = CkPdfW_GetDss(pdf,json); wprintf(L"%s\n",CkJsonObjectW_emit(json)); // The document security store contains certificates, OCSP responses, and CRLs. // The following JSON is a sample of what the /DSS can contain. // Unfortunately, our sample contains /Certs and /OCSPs, but no /CRLs. // It's no problem because whatever JSON you get back, you can use the // following online tool to generate code to parse. // Generate Parsing Code from JSON // The code generated by the online tool for this JSON is shown below.. // { // "/VRI": { // "/EC5BB34CC1F8A0C5FE674427E16E313A08C80808": {} // }, // "/Certs": [ // { // "serial": "02", // "validFrom": "2011-08-07T19:00:00-05:00", // "validTo": "2021-08-10T23:59:59-05:00", // "expired": false, // "subject": { // "CN": "XYZ Corporation", // "O": "XYZ" // }, // "issuer": { // "CN": "XYZ Corporation", // "O": "XYZ" // }, // "keyType": "RSA", // "keySize": "2048", // "der": "MIIDz...Q4Zt" // }, // { // "serial": "01", // "validFrom": "2011-08-07T19:00:00-05:00", // "validTo": "2021-08-10T23:59:59-05:00", // "expired": false, // "subject": { // "CN": "XYZ Corporation", // "O": "XYZ" // }, // "issuer": { // "CN": "XYZ Corporation", // "O": "XYZ" // }, // "keyType": "RSA", // "keySize": "2048", // "der": "MIID...jXYFc=" // }, // { // "serial": "0AA125D6D6321B7E41E405DA3697C215", // "validFrom": "2016-01-07T06:00:00-06:00", // "validTo": "2031-01-07T12:00:00-06:00", // "expired": false, // "subject": { // "CN": "DigiCert SHA2 Assured ID Timestamping CA", // "OU": "www.digicert.com", // "O": "DigiCert Inc", // "C": "US" // }, // "issuer": { // "CN": "DigiCert Assured ID Root CA", // "OU": "www.digicert.com", // "O": "DigiCert Inc", // "C": "US" // }, // "keyType": "RSA", // "keySize": "2048", // "der": "MIIF...OUg==" // }, // { // "serial": "04CD3F8568AE76C61BB0FE7160CCA76D", // "validFrom": "2019-09-30T19:00:00-05:00", // "validTo": "2030-10-17T00:00:00-05:00", // "expired": false, // "subject": { // "CN": "TIMESTAMP-SHA256-2019-10-15", // "O": "DigiCert, Inc.", // "C": "US" // }, // "issuer": { // "CN": "DigiCert SHA2 Assured ID Timestamping CA", // "OU": "www.digicert.com", // "O": "DigiCert Inc", // "C": "US" // }, // "keyType": "RSA", // "keySize": "2048", // "der": "MIIG...MJtPc=" // }, // { // "serial": "0CE7E0E517D846FE8FE560FC1BF03039", // "validFrom": "2006-11-09T18:00:00-06:00", // "validTo": "2031-11-10T00:00:00-06:00", // "expired": false, // "subject": { // "CN": "DigiCert Assured ID Root CA", // "OU": "www.digicert.com", // "O": "DigiCert Inc", // "C": "US" // }, // "issuer": { // "CN": "DigiCert Assured ID Root CA", // "OU": "www.digicert.com", // "O": "DigiCert Inc", // "C": "US" // }, // "keyType": "RSA", // "keySize": "2048", // "der": "MIIDt...FL6Lw8g==" // }, // { // "serial": "E4D34D01798BE686424AF7F6F0C3BF41", // "validFrom": "2015-03-24T10:58:16-05:00", // "validTo": "2039-12-31T23:59:59-06:00", // "expired": false, // "subject": { // "CN": "www.xyz.com" // }, // "issuer": { // "CN": "www.xyz.com" // }, // "keyType": "RSA", // "keySize": "1024", // "der": "MIIB9DCCAWG...UR10lz" // } // ], // "/OCSPs": [ // { // "responseStatus": 0, // "responseTypeOid": "1.3.6.1.5.5.7.48.1.1", // "responseTypeName": "ocspBasic", // "response": { // "responderIdChoice": "KeyHash", // "responderKeyHash": "Reuir/SSy4IxLVGLp6chnfNtyA8=", // "dateTime": "20201005173921Z", // "cert": [ // { // "hashOid": "1.3.14.3.2.26", // "hashAlg": "SHA-1", // "issuerNameHash": "98S+C0C1w0QzPT+uuU1uONr67FE=", // "issuerKeyHash": "Reuir/SSy4IxLVGLp6chnfNtyA8=", // "serialNumber": "0AA125D6D6321B7E41E405DA3697C215", // "status": 0, // "thisUpdate": "20201005173921Z", // "nextUpdate": "20201012173921Z" // } // ] // } // }, // { // "responseStatus": 0, // "responseTypeOid": "1.3.6.1.5.5.7.48.1.1", // "responseTypeName": "ocspBasic", // "response": { // "responderIdChoice": "KeyHash", // "responderKeyHash": "9LbhIB3+Ka7S5GGlsqIlssgXNW4=", // "dateTime": "20201006114501Z", // "cert": [ // { // "hashOid": "1.3.14.3.2.26", // "hashAlg": "SHA-1", // "issuerNameHash": "+YYA+KSr7NIxRSxCjUNQo25SyD0=", // "issuerKeyHash": "9LbhIB3+Ka7S5GGlsqIlssgXNW4=", // "serialNumber": "04CD3F8568AE76C61BB0FE7160CCA76D", // "status": 0, // "thisUpdate": "20201006114501Z", // "nextUpdate": "20201013110001Z" // } // ] // } // } // ] // } // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat. // See this example explaining how this memory should be used: const char * functions. responseDateTime = CkDtObjW_Create(); thisUpdate = CkDtObjW_Create(); nextUpdate = CkDtObjW_Create(); i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"/Certs"); while (i < count_i) { CkJsonObjectW_putI(json,i); serial = CkJsonObjectW_stringOf(json,L"/Certs[i].serial"); validFrom = CkJsonObjectW_stringOf(json,L"/Certs[i].validFrom"); validTo = CkJsonObjectW_stringOf(json,L"/Certs[i].validTo"); expired = CkJsonObjectW_BoolOf(json,L"/Certs[i].expired"); subjectCN = CkJsonObjectW_stringOf(json,L"/Certs[i].subject.CN"); subjectO = CkJsonObjectW_stringOf(json,L"/Certs[i].subject.O"); issuerCN = CkJsonObjectW_stringOf(json,L"/Certs[i].issuer.CN"); issuerO = CkJsonObjectW_stringOf(json,L"/Certs[i].issuer.O"); keyType = CkJsonObjectW_stringOf(json,L"/Certs[i].keyType"); keySize = CkJsonObjectW_stringOf(json,L"/Certs[i].keySize"); der = CkJsonObjectW_stringOf(json,L"/Certs[i].der"); subjectOU = CkJsonObjectW_stringOf(json,L"/Certs[i].subject.OU"); subjectC = CkJsonObjectW_stringOf(json,L"/Certs[i].subject.C"); issuerOU = CkJsonObjectW_stringOf(json,L"/Certs[i].issuer.OU"); issuerC = CkJsonObjectW_stringOf(json,L"/Certs[i].issuer.C"); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"/OCSPs"); while (i < count_i) { CkJsonObjectW_putI(json,i); responseStatus = CkJsonObjectW_IntOf(json,L"/OCSPs[i].responseStatus"); responseTypeOid = CkJsonObjectW_stringOf(json,L"/OCSPs[i].responseTypeOid"); responseTypeName = CkJsonObjectW_stringOf(json,L"/OCSPs[i].responseTypeName"); responseResponderIdChoice = CkJsonObjectW_stringOf(json,L"/OCSPs[i].response.responderIdChoice"); responseResponderKeyHash = CkJsonObjectW_stringOf(json,L"/OCSPs[i].response.responderKeyHash"); CkJsonObjectW_DtOf(json,L"/OCSPs[i].response.dateTime",FALSE,responseDateTime); j = 0; count_j = CkJsonObjectW_SizeOfArray(json,L"/OCSPs[i].response.cert"); while (j < count_j) { CkJsonObjectW_putJ(json,j); hashOid = CkJsonObjectW_stringOf(json,L"/OCSPs[i].response.cert[j].hashOid"); hashAlg = CkJsonObjectW_stringOf(json,L"/OCSPs[i].response.cert[j].hashAlg"); issuerNameHash = CkJsonObjectW_stringOf(json,L"/OCSPs[i].response.cert[j].issuerNameHash"); issuerKeyHash = CkJsonObjectW_stringOf(json,L"/OCSPs[i].response.cert[j].issuerKeyHash"); serialNumber = CkJsonObjectW_stringOf(json,L"/OCSPs[i].response.cert[j].serialNumber"); status = CkJsonObjectW_IntOf(json,L"/OCSPs[i].response.cert[j].status"); CkJsonObjectW_DtOf(json,L"/OCSPs[i].response.cert[j].thisUpdate",FALSE,thisUpdate); CkJsonObjectW_DtOf(json,L"/OCSPs[i].response.cert[j].nextUpdate",FALSE,nextUpdate); j = j + 1; } i = i + 1; } CkPdfW_Dispose(pdf); CkJsonObjectW_Dispose(json); CkDtObjW_Dispose(responseDateTime); CkDtObjW_Dispose(thisUpdate); CkDtObjW_Dispose(nextUpdate); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.