(Java) Get Certificate Policy
Demonstrates how to get a certificate's policy OIDs (if any)
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[])
{
CkCert cert = new CkCert();
boolean 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"));
}
}
}
|