Sample code for 30+ languages & platforms
Java

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 Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.Asn;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Pem;
import com.chilkatsoft.chilkat2.Xml;

public class ChilkatExample {

    public static void main(String[] args) {
        // 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 pem = new Pem();

        pem.setVerboseLogging(true);
        try {
            pem.loadPemFile("qa_data/crl/sampleCrl.pem", "password_not_used");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        int numCrls = pem.getNumCrls();
        int i = 0;

        Asn asn = new Asn();
        Xml xml = new Xml();
        while (i < numCrls) {
            // Get the CRL as base64 (multi-line)
            String crlBase64;
            try {
                crlBase64 = pem.getEncodedItem("crl", "", "base64_mime", i);
            } catch (ChilkatException e) {
                System.out.println(e.getLastErrorText());
                return;
            }

            System.out.println(crlBase64);

            try {
                asn.loadEncoded(crlBase64, "base64");
            } catch (ChilkatException e) {
                System.out.println(e.getLastErrorText());
                return;
            }

            // Convert ASN.1 to XML and load into xml and re-emit for pretty printing..
            xml.loadXml(asn.asnToXml());
            System.out.println(xml.getXml());

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

            System.out.println("-------------------------------------");
            i = i + 1;
        }
    }
}