简体   繁体   中英

Read Certificate in android by bouncy castle

i want to read a certificate in android.

i use below code and the code worked in PC.

try {

        PEMParser pp = new PEMParser(new InputStreamReader(
                new FileInputStream("C:\\Certs\\mmdt.crt")));
        Object o = pp.readObject();
        X509CertificateHolder mmdtCert = (X509CertificateHolder) o;
        pp.close();
        System.out.println(mmdtCert.getSubjectPublicKeyInfo() + " Here");
    } catch (Exception e) {
        e.printStackTrace();
    }

but in android i get below error :

07-06 16:24:20.989: W/System.err(2949): java.lang.ClassCastException: org.bouncycastle.util.io.pem.PemObject

i found the answer but i do not delete this to use by others.

i could not find the reason of problem but i find a new solution.

CertificateFactory factory = CertificateFactory.getInstance("X.509");
X509Certificate x509Server;
ByteArrayInputStream bias = new ByteArrayInputStream(certBytes);
x509Server= (X509Certificate) factory.generateCertificate(bias);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM