Sample code for 30+ languages & platforms
Java

Get Certificate Policy

See more Certificates Examples

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

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    CkCert cert = new CkCert();

    success = cert.LoadFromFile("qa_data/certs/sample.cer");
    if (success == false) {
        System.out.println(cert.lastErrorText());
        return;
        }

    // The certificatePolicies OID is 2.5.29.32
    String oid = "2.5.29.32";
    String strXml = cert.getExtensionAsXml(oid);
    if (cert.get_LastMethodSuccess() == true) {
        System.out.println(strXml);

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

        CkXml xml = new CkXml();
        xml.LoadXml(strXml);
        System.out.println("Policy OID = " + xml.getChildContent("sequence|oid"));
        }
  }
}