Code example for X509Certificate

Methods: getExtensionValue

0
            X509Certificate cert = (X509Certificate)
                    certFactory.generateCertificate(
                            new ByteArrayInputStream(bytes));
            if (isCa(cert)) {
                Log.d(TAG, "got a CA cert");
                mCaCerts.add(cert);
            } else { 
                Log.d(TAG, "got a user cert");
                mUserCert = cert;
            } 
        } catch (CertificateException e) {
            Log.w(TAG, "parseCert(): " + e);
        } 
    } 
 
    private boolean isCa(X509Certificate cert) {
        try { 
            // TODO: add a test about this 
            byte[] basicConstraints = cert.getExtensionValue("2.5.29.19");
            Object obj = new ASN1InputStream(basicConstraints).readObject();
            basicConstraints = ((DEROctetString) obj).getOctets();
            obj = new ASN1InputStream(basicConstraints).readObject();
            return new BasicConstraints((ASN1Sequence) obj).isCA();
        } catch (Exception e) {
Connect your IDE to all the code out there  Get Codota for Java