Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

MFC Examples

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(MFC) Verify a .p7m and get Algorithm Information

Demonstrates how to verify a .p7m and then examine the algorithms used by the signature.

Chilkat C/C++ Library Downloads

MS Visual C/C++ Libs

See Also: Using MFC CString in Chilkat

#include <CkCrypt2.h>
#include <CkJsonObject.h>

void ChilkatSample(void)
    {
    CkString strOut;

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

    CkCrypt2 crypt;

    const char *inFile = "qa_data/p7m/brainpoolP256r1.p7m";
    const char *outFile = "qa_output/something.dat";

    // Verify and extract the signed data.
    bool success = crypt.VerifyP7M(inFile,outFile);
    if (success == false) {
        strOut.append(crypt.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    // Examine details about the signature(s)
    CkJsonObject *json = crypt.LastJsonData();
    json->put_EmitCompact(false);
    strOut.append(json->emit());
    strOut.append("\r\n");

    // Sample output

    // {
    //   "pkcs7": {
    //     "verify": {
    //       "digestAlgorithms": [
    //         "sha256"
    //       ],
    //       "signerInfo": [
    //         {
    //           "cert": {
    //             "serialNumber": "FFFFE552B302FFFFFF1E34C3ACEB2FFFF",
    //             "issuerCN": "The common name of the cert...",
    //             "issuerDN": "",
    //             "digestAlgOid": "2.16.840.1.101.3.4.2.1",
    //             "digestAlgName": "SHA256"
    //           },
    //           "contentType": "1.2.840.113549.1.7.1",
    //           "signingTime": "190409140500Z",
    //           "messageDigest": "lQe9If7vZKFf/NlSYu5Esmlw3phVK/RFsbbb1uH73t8=",
    //           "signingAlgOid": "1.2.840.10045.4.3.2",
    //           "signerDigest": "lQe9If7vZKFf/NlSYu5Esmlw3phVK/RFsbbb1uH73t8=",
    //           "authAttr": [
    //             {
    //               "oid": "1.2.840.113549.1.9.3",
    //               "oidName": "contentType"
    //             },
    //             {
    //               "oid": "1.2.840.113549.1.9.5",
    //               "oidName": "signingTime"
    //             },
    //             {
    //               "oid": "1.2.840.113549.1.9.52",
    //               "oidName": "1.2.840.113549.1.9.52",
    //               "der": "MBs ... AwI="
    //             },
    //             {
    //               "oid": "1.2.840.113549.1.9.4",
    //               "oidName": "messageDigest"
    //             },
    //             {
    //               "oid": "1.2.840.113549.1.9.16.2.47",
    //               "oidName": "signingCertificateV2",
    //               "der": "MCYw .. 7PlQ=="
    //             },
    //             {
    //               "oid": "1.2.840.113549.1.9.20",
    //               "oidName": "1.2.840.113549.1.9.20"
    //             }
    //           ]
    //         }
    //       ]
    //     }
    //   }
    // }

    // Code for parsing the above JSON...
    int i;
    int count_i;
    const char *strVal = 0;
    const char *certSerialNumber = 0;
    const char *certIssuerCN = 0;
    const char *certIssuerDN = 0;
    const char *certDigestAlgOid = 0;
    const char *certDigestAlgName = 0;
    const char *contentType = 0;
    const char *signingTime = 0;
    const char *messageDigest = 0;
    const char *signingAlgOid = 0;
    const char *signerDigest = 0;
    int j;
    int count_j;
    const char *oid = 0;
    const char *oidName = 0;
    const char *der = 0;

    i = 0;
    count_i = json->SizeOfArray("pkcs7.verify.digestAlgorithms");
    while (i < count_i) {
        json->put_I(i);
        strVal = json->stringOf("pkcs7.verify.digestAlgorithms[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json->SizeOfArray("pkcs7.verify.signerInfo");
    while (i < count_i) {
        json->put_I(i);
        certSerialNumber = json->stringOf("pkcs7.verify.signerInfo[i].cert.serialNumber");
        certIssuerCN = json->stringOf("pkcs7.verify.signerInfo[i].cert.issuerCN");
        certIssuerDN = json->stringOf("pkcs7.verify.signerInfo[i].cert.issuerDN");
        certDigestAlgOid = json->stringOf("pkcs7.verify.signerInfo[i].cert.digestAlgOid");
        certDigestAlgName = json->stringOf("pkcs7.verify.signerInfo[i].cert.digestAlgName");
        contentType = json->stringOf("pkcs7.verify.signerInfo[i].contentType");
        signingTime = json->stringOf("pkcs7.verify.signerInfo[i].signingTime");
        messageDigest = json->stringOf("pkcs7.verify.signerInfo[i].messageDigest");
        signingAlgOid = json->stringOf("pkcs7.verify.signerInfo[i].signingAlgOid");
        signerDigest = json->stringOf("pkcs7.verify.signerInfo[i].signerDigest");
        j = 0;
        count_j = json->SizeOfArray("pkcs7.verify.signerInfo[i].authAttr");
        while (j < count_j) {
            json->put_J(j);
            oid = json->stringOf("pkcs7.verify.signerInfo[i].authAttr[j].oid");
            oidName = json->stringOf("pkcs7.verify.signerInfo[i].authAttr[j].oidName");
            der = json->stringOf("pkcs7.verify.signerInfo[i].authAttr[j].der");
            j = j + 1;
        }

        i = i + 1;
    }

    delete json;

    strOut.append("Success!");
    strOut.append("\r\n");


    SetDlgItemText(IDC_EDIT1,strOut.getUnicode());

    }

 

© 2000-2022 Chilkat Software, Inc. All Rights Reserved.