public byte[] getExtensionValue(String oid) {
    Extension ext = getExtension(new ASN1ObjectIdentifier(oid));

    if (ext != null) {
      try {
        return ext.getExtnValue().getEncoded();
      } catch (Exception e) {
        throw new RuntimeException("error encoding " + e.toString());
      }
    }

    return null;
  }
  public String toString() {
    StringBuffer buf = new StringBuffer();
    String nl = System.getProperty("line.separator");

    buf.append("      userCertificate: ").append(this.getSerialNumber()).append(nl);
    buf.append("       revocationDate: ").append(this.getRevocationDate()).append(nl);
    buf.append("       certificateIssuer: ").append(this.getCertificateIssuer()).append(nl);

    Extensions extensions = c.getExtensions();

    if (extensions != null) {
      Enumeration e = extensions.oids();
      if (e.hasMoreElements()) {
        buf.append("   crlEntryExtensions:").append(nl);

        while (e.hasMoreElements()) {
          ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
          Extension ext = extensions.getExtension(oid);
          if (ext.getExtnValue() != null) {
            byte[] octs = ext.getExtnValue().getOctets();
            ASN1InputStream dIn = new ASN1InputStream(octs);
            buf.append("                       critical(").append(ext.isCritical()).append(") ");
            try {
              if (oid.equals(X509Extension.reasonCode)) {
                buf.append(CRLReason.getInstance(ASN1Enumerated.getInstance(dIn.readObject())))
                    .append(nl);
              } else if (oid.equals(X509Extension.certificateIssuer)) {
                buf.append("Certificate issuer: ")
                    .append(GeneralNames.getInstance(dIn.readObject()))
                    .append(nl);
              } else {
                buf.append(oid.getId());
                buf.append(" value = ").append(ASN1Dump.dumpAsString(dIn.readObject())).append(nl);
              }
            } catch (Exception ex) {
              buf.append(oid.getId());
              buf.append(" value = ").append("*****").append(nl);
            }
          } else {
            buf.append(nl);
          }
        }
      }
    }

    return buf.toString();
  }
  private Set getExtensionOIDs(boolean critical) {
    Extensions extensions = c.getExtensions();

    if (extensions != null) {
      Set set = new HashSet();
      Enumeration e = extensions.oids();

      while (e.hasMoreElements()) {
        ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
        Extension ext = extensions.getExtension(oid);

        if (critical == ext.isCritical()) {
          set.add(oid.getId());
        }
      }

      return set;
    }

    return null;
  }
  private X500Name loadCertificateIssuer(boolean isIndirect, X500Name previousCertificateIssuer) {
    if (!isIndirect) {
      return null;
    }

    Extension ext = getExtension(Extension.certificateIssuer);
    if (ext == null) {
      return previousCertificateIssuer;
    }

    try {
      GeneralName[] names = GeneralNames.getInstance(ext.getParsedValue()).getNames();
      for (int i = 0; i < names.length; i++) {
        if (names[i].getTagNo() == GeneralName.directoryName) {
          return X500Name.getInstance(names[i].getName());
        }
      }
      return null;
    } catch (Exception e) {
      return null;
    }
  }