DEROctetString oct = (DEROctetString) (new DERInputStream(new ByteArrayInputStream(extvalue)).readObject()); ASN1Sequence seq = (ASN1Sequence)new DERInputStream(new ByteArrayInputStream(oct.getOctets())).readObject();
DEROctetString oct = (DEROctetString) (new ASN1InputStream(new ByteArrayInputStream(extvalue)).readObject()); ASN1Sequence seq = (ASN1Sequence)new ASN1InputStream(new ByteArrayInputStream(oct.getOctets())).readObject();
    public static String getCertificatePolicyId(X509Certificate cert, int pos)        throws IOException {        byte[] extvalue = cert.getExtensionValue(X509Extensions.CertificatePolicies.getId());        if (extvalue == null) {            return null;        }        DEROctetString oct = (DEROctetString) (new DERInputStream(new ByteArrayInputStream(extvalue)).readObject());        ASN1Sequence seq = (ASN1Sequence)new DERInputStream(new ByteArrayInputStream(oct.getOctets())).readObject();        // Check the size so we don't ArrayIndexOutOfBounds        if (seq.size() < pos+1) {            return null;        }        PolicyInformation pol = new PolicyInformation((ASN1Sequence)seq.getObjectAt(pos));        String id = pol.getPolicyIdentifier().getId();        return id;    } // getCertificatePolicyId