Sample code for 30+ languages & platforms
PHP

Convert CRL PEM to XML

See more PEM Examples

Loads a CRL (Certificate Revocation List) from the PEM file format and converts to XML to allow for visual examination and parsing.

Note: This example requires Chilkat v9.5.0.77 or greater.

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\Asn;
use Chilkat2\Pem;
use Chilkat2\Xml;

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

// This example requires Chilkat v9.5.0.77 or greater.
$pem = new Pem();

$pem->VerboseLogging = true;
try {
    $pem->LoadPemFile('qa_data/crl/sampleCrl.pem', 'password_not_used');
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

$numCrls = $pem->NumCrls;
$i = 0;

$asn = new Asn();
$xml = new Xml();
while ($i < $numCrls) {
    // Get the CRL as base64 (multi-line)
    try {
        $crlBase64 = $pem->GetEncodedItem('crl', '', 'base64_mime', $i);
    } catch (\Chilkat2\Exception $e) {
        echo $e->getMessage(), "\n";
        exit;
    }

    echo $crlBase64, "\n";

    try {
        $asn->LoadEncoded($crlBase64, 'base64');
    } catch (\Chilkat2\Exception $e) {
        echo $e->getMessage(), "\n";
        exit;
    }

    // Convert ASN.1 to XML and load into xml and re-emit for pretty printing..
    $xml->LoadXml($asn->AsnToXml());
    echo $xml->GetXml(), "\n";

    // Use this online tool to generate parsing code from CRL XML:
    // Generate Parsing Code from XML

    echo "-------------------------------------\n";
    $i = $i + 1;
}