Trust Certificate Authority in Android

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Feb 16, 2015 4:52:22 PM via Website

I am trying to trust a Certificate Authority in my Android application.

certData = Base64.decode(Base64EncodedCACert);

    CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
    InputStream in = new ByteArrayInputStream(certData);
    X509Certificate cert = (X509Certificate)certFactory.generateCertificate(in);

    //Create a KeyStore containing trusted CA
    KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    keyStore.setCertificateEntry("CA", cert);

    //Create a TrustManager that trusts the CA in our KeyStore 
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());

    //Create an SSLContext that use the TrustManager
    SSLContext context = SSLContext.getInstance("SSL");
    context.init(null, tmf.getTrustManagers(), null);


Is this enough to trust the CA ? How can I check it ?