Sample code for 30+ languages & platforms
C++

Get Certificate Policy

See more Certificates Examples

Demonstrates how to get a certificate's policy OIDs (if any)

Chilkat C++ Downloads

C++
#include <CkCert.h>
#include <CkXml.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkCert cert;

    success = cert.LoadFromFile("qa_data/certs/sample.cer");
    if (success == false) {
        std::cout << cert.lastErrorText() << "\r\n";
        return;
    }

    // The certificatePolicies OID is 2.5.29.32
    const char *oid = "2.5.29.32";
    const char *strXml = cert.getExtensionAsXml(oid);
    if (cert.get_LastMethodSuccess() == true) {
        std::cout << strXml << "\r\n";

        // Sample result:
        // <sequence><sequence><oid>2.16.840.1.101.2.1.11.39</oid></sequence></sequence>

        CkXml xml;
        xml.LoadXml(strXml);
        std::cout << "Policy OID = " << xml.getChildContent("sequence|oid") << "\r\n";
    }
    }